Answer the question
In order to leave comments, you need to log in
How to make React dynamic import?
Good afternoon!
I'm trying to make a dynamic import in React.
/*
Переменная откуда я беру путь до компонента
*/
const steps = [
{
name: 'Шаг 1',
component: './steps/step1.jsx'
},
{
name: 'Шаг 2',
component: './steps/step2.jsx'
}
]
/*
Динамический импорт
*/
const Step = React.lazy(()=> import(steps[0].component))
<React.Suspense fallback={<div>Loading...</div>}>
<Step/>
</React.Suspense>
/*
При таком варианте все работает
*/
const Step = React.lazy(()=> import('./steps/step1.jsx'))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question