Wrap ES6 module around reactive component

I am using react and ES6.

I have a file named:

mainComponent.js

      

To use this in other files, I just import the component.

Now I want to wrap the component (s) inside an ES6 module so that I just need to use imports in the module to access the component (s)

For example:

If I had 2 components:

reactComponent1.js
reactComponent2.js

      

Then I want to wrap these 2 components in wrapperModule.js

So, if I want to use these components, I just import wrapperModule.js

Is it possible? If so, how?

+3


source to share


1 answer


You can use it like this

wrapperModule.js
export { ReactComponent1 } from 'path/to/reactComponent1'
export { ReactComponent2 } from 'path/to/reactComponent2'

      



And use it in your file like this

import {ReactComponent1, ReactComponent2 } from 'path/to/wrapperModule'

      

+1


source







All Articles