Using React.lazy with TypeScript

前端 未结 4 1780
情话喂你
情话喂你 2021-01-08 00:17

I am trying to use React.lazy for code splitting in my TypeScript React app.

All I am doing is changing that line:

import {ScreensProductList} from \         


        
4条回答
  •  半阙折子戏
    2021-01-08 00:36

    You can create an index.ts file where you can export all your components like in this eg. :

    export {default as YourComponentName} from "./YourComponentName";
    

    After that you can use React.lazy:

    React.lazy(() => import("../components/folder-name-where-the-index-file-is-created").then(({YourComponentName}) => ({default: YourComponentName})))
    

提交回复
热议问题