Why shouldn’t JSX props use arrow functions or bind?

Why you shouldn’t use inline arrow functions in JSX props Using arrow functions or binding in JSX is a bad practice that hurts performance, because the function is recreated on each render. Whenever a function is created, the previous function is garbage collected. Rerendering many elements might create jank in animations. Using an inline arrow … Read more

How to import and export components using React + ES6 + webpack?

Try defaulting the exports in your components: import React from ‘react’; import Navbar from ‘react-bootstrap/lib/Navbar’; export default class MyNavbar extends React.Component { render(){ return ( <Navbar className=”navbar-dark” fluid> … </Navbar> ); } } by using default you express that’s going to be member in that module which would be imported if no specific member name … Read more

Object.is vs ===

=== is called strict comparison operator in JavaScript. Object.is and strict comparison operator behave exactly the same except for NaN and +0/-0. From MDN: Object.is() method is not the same as being equal according to the === operator. The === operator (and the == operator as well) treats the number values -0 and +0 as … Read more

JavaScript (ES6) const with curly braces [duplicate]

It’s a destructuring assignment. Specifically, an object destructuring assignment. It might help to see it rewritten in a more verbose way. const abc = Object.abc; const def = Object.def; It’s a shorthand way to initialise variables from object properties. const name = app.name; const version = app.version; const type = app.type; // Can be rewritten … Read more

How to implement private method in ES6 class with Traceur [duplicate]

There are no private, public or protected keywords in current ECMAScript 6 specification. So Traceur does not support private and public. 6to5 (currently it’s called “Babel”) realizes this proposal for experimental purpose (see also this discussion). But it’s just proposal, after all. So for now you can just simulate private properties through WeakMap (see here). … Read more

ES6 getter/setter with arrow function

According to the ES2015 grammar, a property on an object literal can only be one of three things: PropertyDefinition: IdentifierReference PropertyName : AssignmentExpression MethodDefinition The only one of these type that allows a leading get is MethodDefinition: MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody } GeneratorMethod get PropertyName ( ) { FunctionBody } set … Read more

How to import jquery using ES6 syntax?

index.js import {$,jQuery} from ‘jquery’; // export for others scripts to use window.$ = $; window.jQuery = jQuery; First, as @nem suggested in comment, the import should be done from node_modules/: Well, importing from dist/ doesn’t make sense since that is your distribution folder with production ready app. Building your app should take what’s inside … Read more