T
T
Timofei19972022-02-24 19:37:05
React
Timofei1997, 2022-02-24 19:37:05

How does React.lazy work?

Hello, please tell me why if I write AddTodo like this:
const AddTodo = React.lazy(() => import('./Todo/AddTodo') )

everything works, but if:
const AddTodo = React.lazy(( ) => {
import('./Todo/AddTodo')
} )

then nothing works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Megas, 2022-02-24
@Timofei1997

Because you need to return a value if you use curly braces:

const AddTodo = React.lazy(() => {
     return import('./Todo/AddTodo');
} )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question