- React Apps are basically a collection of interactive Components.
- Similarly, we can also import user-defined classes, components or even a part of the same.
- Using ES2015 which is shortly called as ES5, every module can have a default export or may export several named parameters, and if it is possible to export it will surely be possible to import the same.
Importing default export:
Every module to have at most one default export.
In order to import the default export from a file, we can use only the address and use the keyword import before it, or we can give a name to the import making the syntax as the following.
import GIVEN_NAME from ADDRESS
// Example: Importing Module
import ReactDOM from 'react-dom';
// Example: Importing Module
import ReactDOM from 'react-dom';
Importing named values:
Every module can have several named parameters and in order to import one we should use the syntax as follows.
import { PARA_NAME } from ADDRESS
And similarly for multiple such imports we can use a comma to seperate two parameter name within the curly braces.
Importing a combination of Default Exports and Named Values:
The title makes it clear what we need to see is that the syntax of the same. In order to import a combination, we should use the following syntax.
import GIVEN_NAME, { PARA_NAME, ... } from ADDRESS
// Example: Importing combination
import React, {Component} from 'react';
// Example: Importing combination
import React, {Component} from 'react';
No comments:
Post a Comment