With the help of the browser’s LocalStorage, we can keep track of the number of visits of a user on the website or a particular webpage. Based on this data, customized alerts, messages or information can be shown to the user.
[Read More]React JS Render Form With Dynamic Conditional Fields
Show or hide based on the parent field value
React JS Render Form With Dynamic Data From Backend API
including field validations
We need to plot a form whose entire fields are coming from the backend. Since the fields are not known in advance, we cannot add them statically. The data about each field, such as its id to save with, name, validations, etc. all comes in the API response too.
For the given scenario, I have used React Hook Form. The demo and example code for a dynamic questionnaire is shared below.
[Read More]Exclude Yourself From Google Analytics Without Filtering IP Addresses or Using Extensions
Including localhost calls. Works regardless of location, browser, or device.
JavaScript Find Total Time Duration
Excluding overlapping and idle times
Get User Country and Region on Browser With JavaScript Only
Without Using IP Address
Detecting the country and region of the visiting user on the browser is certainly possible using JavaScript alone, without using any third-party geolocation service such as ipstack. The only consideration: It may not be accurate, and depend on the timezone selected by the user on their system, which can be changed. But since hardly anybody changes their system-auto-detected timezone nowadays (except for testing, which I have shown below), it is a good enough and cheap detection method for non-critical use cases.
[Read More]JavaScript Generate Your Own Random Number Without Math Random
A Custom Code for Finding Pseudo-generated Number
Compare Two JavaScript Objects and Get the Updated Keys
Where the Value of the Key Has Changed.
We have two similar JavaScript objects and are interested in finding which key(s), if any, have changed at the first level. A key in the object could hold any data type in its value, including array and object, and it could also be deeply nested. The change could mean anything, such as added, added to, removed, removed from, modified, shuffled, etc.
You may require this kind of key identification in cases where you compare the old and new states, such as previous and new filters, and figure out what exactly changed.
[Read More]JavaScript Token Bucket Algorithm
And its Possible Uses
JavaScript: Change the Behavior of a Class Method at Runtime
Useful Strategy to Perform Different Operations Without Repeated if Else or Switch Statements
Recently I came across a problem where I needed to perform two different sets of operations throughout the application for two types of users. The trouble was:
- I needed to turn on or off an operation based on certain condition, which would only be known once the user was logged in, not at the beginning.