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. The only thing I can do is:
import addons from "react/addons"; let PureRenderMixin = addons.addons.PureRenderMixin;
I hope there is a better way.
To conditionally import an ES6 module with JavaScript, we can use the import function. const myModule = await import(moduleName); in an async function to call import with the moduleName string to import the module named moduleName . And then we get the module returned by the promise returned by import with await .
The ES6 module standard has two parts: Declarative syntax (for importing and exporting) Programmatic loader API: to configure how modules are loaded and to conditionally load modules.
Importing can be done in various ways:Node js doesn't support ES6 import directly. If we try to use import for importing modules directly in node js it will throw out the error.
With the help of ES6, we can create modules in JavaScript. In a module, there can be classes, functions, variables, and objects as well. To make all these available in another file, we can use export and import. The export and import are the keywords used for exporting and importing one or more members in a module.
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.js export default 'A'; export var B = 'B'; //script.js import A from './a.js'; //import value on default export import {B} from './a.js'; // import value by its name console.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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With