Skip to content Skip to sidebar Skip to footer

How To Import Part Of Object In Es6 Modules

In the react documentation I found this way to import PureRenderMixin var PureRenderMixin = require('react/addons').addons.PureRenderMixin; How can it be rewritten in ES6 style. T

Solution 1:

Unfortunately import statements does not work like object destructuring. Curly braces here mean that you want to import token with this name but not property of default export. Look at this pairs of import/export:

//module.jsexportdefault'A';
 exportvar B = 'B';

 //script.jsimport A from'./a.js';  //import value on default exportimport {B} from'./a.js'; // import value by its nameconsole.log(A, B); // 'A', 'B'

For your case you can import whole object and make a destructuring assignment

import addons from"react/addons";
 let {addons: {PureRenderMixin}} = addons;

Solution 2:

importPureRenderMixinfrom'react-addons-pure-render-mixin';

See example here.

Post a Comment for "How To Import Part Of Object In Es6 Modules"