What is ES6 Modules (Export and Import)?
![]() |
| ES6 Modules Export and Import | IndianTechnoEra |
ES Modules make accessible to export the components in react
There are two types of ES modules
- Export
- Import
What is ES Export Modules?
It export the component that can be import and can be used by another component and in index. We can export by two method
- By Named :
- By Default :
What is Named exports show with example?
It will export only particular variable or particular part
Example: Exporting single variable one by one
App1.js
export const var1= 'My Name is sam';
export const var2= 'Last name is Edward';
Example: Exporting single variable all at once
App2.js
const var3= 'My Name is sam';
const var4= 'Last name is Edward';
export {var3, var4}
What is Default exports show with example?
It will export the whole component better with functional and class instead of variable type
Example: Exporting default to a component
App3.js
const fullName = () =>{
const fName = "Sam"
const lName = "Edward"
return `My name is ${fName} ${lName}`
}
export default App3;
What is Import show with example?
By Import we import modules into a file in tow ways, named exported and default exported component
Importing named exported component
import {var1, var2} from './App1.js'
import App3 from './App3.js'
