user8398743
user8398743

Reputation:

Wrap ES6 Module around React Component

I am using react and ES6.

I have a file called:

mainComponent.js

To use this on other files I just import the component.

What I want to do now is to wrap the component(s) inside an ES6 Module so that I just need to use import on the module to have access to the component(s)

For example:

If I had 2 component:

reactComponent1.js
reactComponent2.js

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

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

Is this possible? If so how?

Upvotes: 3

Views: 216

Answers (1)

Murat Karagöz
Murat Karagöz

Reputation: 37594

You could 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'

Upvotes: 2

Related Questions