Answer the question
In order to leave comments, you need to log in
What is the best way to import components in React?
The project gets a lot of shared components (buttons, switches, etc.). And in each component you have to import them separately.
There is an option to create a module in which to import all these components and return
export default {
Component1,
Component2,
Component3
}
Answer the question
In order to leave comments, you need to log in
We use this approach. I'll show you with an example action from redux, but it can also be used with components.
An index.js file is created in the directory with shared components. It exports all named exports from files in this folder like this: Index.js
file:
export * from './auth';
export * from './user';
export * from './interfaces';
export * from './search';
export * from './catalog';
export * from './classifier';
export const getUserToken = ( login, password ) => (dispatch, getState) => {...}
export const registerUser = ( newUserData ) => ( dispatch, getState ) => {...}
import { getUserToken, doSmsng, doSmsngElse } from '../../../_actions';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question