Using React.lazy with TypeScript

前端 未结 4 1745
情话喂你
情话喂你 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:30

    Another way

    const UsersList = () => (
      ..JSX
    )
    
    export default UsersList as React.FC;
    

    Or in old class components

    class UsersList extends Component {
      render(){
    
      }
    }
    
    
    export default UsersList as React.ComponentType
    

    and while importing using React.lazy

    React.lazy( ()=> import("./UsersList") )
    

提交回复
热议问题