Skip to content

Commit 9c12d13

Browse files
committed
yh: modify named imports
1 parent 25e4c8b commit 9c12d13

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,27 +364,41 @@ import `underscore`
364364

365365
> It is important to note that simply **importing an entire file will execute all code at the top level of that file**.
366366
367-
We can also use destructuring to import a list of values from a file:
367+
Similar to Python, we have named imports:
368368

369369
```javascript
370370
import { sumTwo, sumThree } from 'math/addition'
371371
```
372372

373-
Similar to Python, we have named imports:
373+
We can also rename the named imports:
374374

375375
```javascript
376-
import {
377-
sumTwo as addTwoNumbers,
376+
import {
377+
sumTwo as addTwoNumbers,
378378
sumThree as sumThreeNumbers
379379
} from 'math/addition'
380380
```
381381

382-
And lastly, we can **import all the things**:
382+
In addition, we can **import all the things** (also called namespace import):
383383

384384
```javascript
385385
import * as util from 'math/addition'
386386
```
387387

388+
Lastly, we can use destructuring to import a list of values from a file:
389+
390+
```javascript
391+
import * as addtionUtil from 'math/addtion';
392+
const { sumTwo, sumThree } = addtionUtil;
393+
```
394+
395+
or when we are importing the default object but we want to grab some of the functions on the object:
396+
397+
```javascript
398+
import React from 'react';
399+
const { Component, PropTypes } = React;
400+
```
401+
388402
> **Note**: Values that are exported are **bindings**, not references. Therefore, changing the binding of a variable in one module will affect the value within the exported module. Avoid changing the public interface of these exported values.
389403
390404
<sup>[(back to table of contents)](#table-of-contents)</sup>

0 commit comments

Comments
 (0)