Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
79
rated 0 times [  80] [ 1]  / answers: 1 / hits: 32337  / 9 Years ago, fri, may 8, 2015, 12:00:00

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.


More From » module

 Answers
13

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;

[#66680] Wednesday, May 6, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quentinaveryb

Total Points: 102
Total Questions: 100
Total Answers: 93

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
quentinaveryb questions
Thu, Aug 6, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;