javascript
Setting onSubmit in React.js
In your doSomething() function, pass in the event e and use e.preventDefault().
SyntaxError: Unexpected token o in JSON at position 1
The JSON you posted looks fine, however in your code, it is most likely not a JSON string anymore, but already a JavaScript object. This means, no more parsing is necessary. You can test this yourself, e.g. in Chrome’s console: JSON.parse() converts the input into a string. The toString() method of JavaScript objects by default returns [object Object], resulting … Read more
What does on() in JavaScript do?
The on() method attaches one or more event handlers for the selected elements and child elements. Read more about jQuery on() Method As per your code $(document).on(‘click’,’#add’), I guess it’s creating a delegated event. It will directly fired on #add id element
Regular expression : match either of two conditions?
In your regex, the two alternative branches are anchored separately: (^([a-zA-Z]){2}([0-9]){6}) – 2 letters and 6 digits at the start of the string | – or ([0-9]*)?$ – optional zero or more digits at the end of the string You need to adjust the boundaries of the group: See the regex demo. Now, the pattern will match: ^ – start … Read more
Timers in React Native (this.setTimeout)
Settimeout and setInterval still work in react-native. BUT you have to use it in the right way: Here is one of many ways to implement a timeout in React that I’m usually used: With this approach you don’t have to worry about memory leak anymore. Just simple and straight forward. There is an excellent article … Read more
React Context vs React Redux, when should I use each one?
As Context is no longer an experimental feature and you can use Context in your application directly and it is going to be great for passing down data to deeply nested components which what it was designed for. As Mark Erikson has written in his blog: If you’re only using Redux to avoid passing down props, context could … Read more
Javascript versioning to avoid caching, difference in these practices?
Using an updated querystring is a bad solution. See what Steve souders has so say about it: http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ The ideal method is to rename the file itself. Some people prefer using the time stamp of the last modification date, which i think is a problem. In modern web development you really need to optimize your page … Read more
How to detect Safari, Chrome, IE, Firefox and Opera browser?
Googling for browser reliable detection often results in checking the User agent string. This method is not reliable, because it’s trivial to spoof this value.I’ve written a method to detect browsers by duck-typing. Only use the browser detection method if it’s truly necessary, such as showing browser-specific instructions to install an extension. Use feature detection when possible. Demo: https://jsfiddle.net/6spj1059/ Run … Read more
Javascript versioning to avoid caching, difference in these practices?
Using an updated querystring is a bad solution. See what Steve souders has so say about it: http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ The ideal method is to rename the file itself. Some people prefer using the time stamp of the last modification date, which i think is a problem. In modern web development you really need to optimize your page … Read more