From b7dae56395cafc3194ea872c26e858f3c77adf7d Mon Sep 17 00:00:00 2001 From: Asabeneh Date: Sat, 3 Oct 2020 18:42:17 +0300 Subject: [PATCH] modules example added --- .../02_introduction_to_react.md | 2 -- 03_Day_Setting_Up/03_day_setting_up.md | 27 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/02_Day_Introduction_to_React/02_introduction_to_react.md b/02_Day_Introduction_to_React/02_introduction_to_react.md index 1867921..edeb26f 100644 --- a/02_Day_Introduction_to_React/02_introduction_to_react.md +++ b/02_Day_Introduction_to_React/02_introduction_to_react.md @@ -11,8 +11,6 @@ Asabeneh Yetayeh
October, 2020 - - [<< Day 1](../01_Day_JavaScript_Refresher/01_javascript_refresher.md) | [Day 3 >>](../03_Day_Setting_Up/03_day_setting_up.md) diff --git a/03_Day_Setting_Up/03_day_setting_up.md b/03_Day_Setting_Up/03_day_setting_up.md index 0d48075..b63d528 100644 --- a/03_Day_Setting_Up/03_day_setting_up.md +++ b/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