ES6 Modules Export and Import | IndianTechnoEra - IndianTechnoEra
Latest update Android YouTube

ES6 Modules Export and Import | IndianTechnoEra

 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

  1. Export 
  2. 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 

  1. By Named : 
  2. 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'

إرسال تعليق

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.