React · Junior · Question 37 of 75

Why does lazy(() => import('./Chart')) fail if Chart.tsx has only export function Chart?

Explanation

The promise from import() must resolve to an object with a default field. For a named export, map it: lazy(() => import('./Chart').then(m => ({ default: m.Chart }))). TypeScript and function components are fully supported.

Further reading

Problem with a question

React · Junior · question 37

Test yourself

Take the React · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz