What does @@ (“at at”) mean in ES6 JavaScript?

@@ describes what’s called a well-known symbol. (Note that it isn’t actually valid syntax in JS.) According to the ES6/ES20151 specification: Well-known symbols are built-in Symbol values that are explicitly referenced by algorithms of this specification. They are typically used as the keys of properties whose values serve as extension points of a specification algorithm. … Read more

ES6 modules: Export single class of static methods OR multiple individual methods

A class of just static methods feels like a bit of a ‘code smell’ Yes indeed. You don’t need a class structure here! Just export a normal “module” object: //—— myMethods.js —— export default { myMethod1() { console.log(‘foo’); }, myMethod2(args…) { console.log(‘bar’); } }; I do recommend your second approach with multiple exports, though. exporting … Read more

Passing in NULL as a parameter in ES6 does not use the default parameter when one is provided

This is not that obvious I’ve read some comments of why undefined is completely different than null and that’s why it explains the current behavior of default parameters. One could argue that explicitly passing undefined should not trigger the default value substitution because when I have a function: const f = (x = ‘default’) => … Read more

Web Workers – How To Import Modules

ES2015 modules in Workers are available in Safari and in Chromium browsers. If other browsers / versions are your target, you still need to use importScripts(). When available, you create a module-worker like this: new Worker(“worker.js”, { type: “module” }); See: https://html.spec.whatwg.org/#module-worker-example These are the bug-reports for each browser: Firefox: Fixed! expected in version 111 … Read more

How to destructure an object with a key containing a hyphen into a variable? [duplicate]

Just like you cannot declare a variable with a hyphen, you can’t destructure directly to one. You will need to rename your variable to something else in order to access it on the current scope. You can use the following destructuring syntax to do that: const x = { “accept-ranges”:”bytes”, “cache-control”:”public, max-age=0″, “content-length”:”1174″, “content-type”:”application/json”, date:”Mon, … Read more

React – defaultProps vs ES6 default params when destructuring (performances issues)

I talked to several people on Discord #reactiflux channel and actually got the answer I was looking for. There are basically three use-case with React components, and in some of them, destructuring params will impact performances so it is important to understand what’s going on under the hood. Stateless functional component const MyComponent = ({ … Read more

When user is not logged in redirect to login. Reactjs [duplicate]

See this answer https://stackoverflow.com/a/43171515/208079. Perhaps someone with more rep than me can mark this as a duplicate. The basic idea is to wrap routes that require authentication with a custom component (PrivateRoute in the example below). PrivateRoute will use some logic to determine if the user is authenticated and then either; allow the requested route … Read more