ES6 template literals vs. concatenated strings

If you are using template literals only with placeholders (e.g. `Hello ${person.name}`) like in the question’s example, then the result is the same as just concatenating strings. Subjectively it looks better and is easier to read, especially for multi-line strings or strings containing both ‘ and ” since you don’t have to escape those characters … Read more

Active link with React-Router?

This is an old, outdated answer for React Router v4 <Link> no longer has the activeClassName or activeStyle properties. In react-router v4 you have to use <NavLink> if you want to do conditional styling: const Router = () => ( <BrowserRouter> <div> <Nav> <NavLink exact activeClassName=”is-active” to=”https://stackoverflow.com/”>Home</NavLink> <NavLink activeClassName=”is-active” to=’/about’>About</NavLink> </Nav> <Match pattern=”https://stackoverflow.com/” exactly component={Home} … Read more

React, ES6 – getInitialState was defined on a plain JavaScript class

getInitialState is not used in ES6 classes. Instead assign this.state in the constructor. propTypes should be a static class variable or assigned to the class, it should not be assigned to component instances. Member methods are not “auto-bound” in ES6 classes. For methods used as callbacks, either use class property initializers or assign bound instances … Read more

Curly brackets (braces) in Node.js ‘require’ statement

The second example uses destructuring. This will call the specific variable (including functions) that are exported from the required module. For example (functions.js): module.exports = { func1, func2 } is included in your file: const { func1, func2 } = require(‘./functions’) Now you can call them individually, func1() func2() as opposed to: const Functions = … Read more

ES2015 import doesn’t work (even at top-level) in Firefox

Actually the error you got was because you need to explicitly state that you’re loading a module – only then the use of modules is allowed: <script src=”https://stackoverflow.com/questions/37624819/t1.js” type=”module”></script> I found it in this document about using ES6 import in browser. Recommended reading. Fully supported in those browser versions (and later; full list on caniuse.com): … Read more