3. Imports and Exports Modules - florypaul/ReactJS GitHub Wiki
In React we create re-usable modules of code.
- Using default export - you can import the component directly in the file
example in person.js:
const person= {
name: 'John Smith'
}
export default empName
import person.js from './person.js';
- Named export - But if you are using multiple modules in a JS file and export with it name then we use curly braces while importing example in Utilities.js
export const name ={ name : 'John Smith' }
export const base = { id : "1" }
import {name} from './Utilities.js'
import {base} from './Utilities.js'
- We can also use '*' for importing all the modules from a single js file with alias name
import * as bundle from "./Utilities.js"