Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import multiple components from one general folder?

Tags:

reactjs

I have many components in a components folder. How can I import them in one line?

For example I have this:

import FormField from "./../components/FormField";
import MultiSelect from "./../components/MultiSelect";

but I want to import it like this:

import {MultiSelect, FormField} from "./../components";

which is not working.

like image 727
Larisa Avatar asked Oct 28 '25 07:10

Larisa


2 Answers

To do like this:

import { MultiSelect, FormField } from "./../components";

In your components folder, create new file: index.js with

export { default as FormField } from './FormField';
export { default as MultiSelect} from './MultiSelect';

like image 50
namth Avatar answered Oct 31 '25 12:10

namth


Just make index.js in components folder

export * from './FormField';
export * from './MultiSelect';

After this you can easily access.

import {MultiSelect,FormField} from "./../components";
like image 26
Saddam Husen Avatar answered Oct 31 '25 12:10

Saddam Husen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!