modules example added

pull/12/head
Asabeneh 4 years ago
parent 746b724a1a
commit b7dae56395

@ -11,8 +11,6 @@
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
<small> October, 2020</small>
</sub>
</div>
</div>
[<< Day 1](../01_Day_JavaScript_Refresher/01_javascript_refresher.md) | [Day 3 >>](../03_Day_Setting_Up/03_day_setting_up.md)

@ -68,15 +68,34 @@ In react we do not use link to access modules or packages instead we import the
export const addTwo = (a, b) => a + b
export const multiply = (a, b) => a * b
export const subtract = (a, b) => a - b
default export doSomeMath = () => {
export default (function doSomeMath() {
return {
addTwo, multiply, subtract
addTwo,
multiply,
subtract,
}
})()
```
}
Now let's import the _math.js_ modules to a different file.
```js
// index.js
// to import the doSomeMath from the math.js with or without extension
import doSomeMath from './math.js'
// to import the other modules
// since these modules were not exported as default we have to desctructure
import { addTwo, multiply, subtract } from './math.js'
import * as everything from './math.js' // to import everything renaming
console.log(addTwo(5, 5))
console.log(doSomeMath.addTwo(5, 5))
console.log(everything)
```
Now let's import the _math.js_ modules to a different file
After this, when you see _import React from 'react'_ or _import ReactDOM from 'react-dom'_ you will not be surprised.
## Package

Loading…
Cancel
Save