Using import and export keyword in react js

If you coding in react them you have to understand how to use import and export statement in javascript. These command are native in javascript and they are not related to react or some other framework.

Import keyword is used to import some modules / code / variables and export keyword is used to export some object, functions or primitive values.

 

Let start with first example:

we created separated function in file logger.js and use export command in order to export function logger.

We want to import and use this function. We can do it on next way:

 

Another example will demonstrate when we have more items for export:

 

If you want to use all exported items then take a look on example below:

 

One note regarding import keyword,  import can be called as function and then import returns promise object.

We already used import keyword as function when we demonstrated lazy loading react component.

You may also like...

Leave a Reply