Dynamic import in react not working when trying to import a component in another directory

后端 未结 2 1005
滥情空心
滥情空心 2021-01-05 14:19

Hello everyone I have been trying dynamic imports in react for rendering my components for an app created with CRA (create-react-app) and while it works perfectly for some c

2条回答
  •  猫巷女王i
    2021-01-05 14:54

    If FooterComp is under src, the path should be './FooterComp/Footer' not '../FooterComp/Footer'


    Edit

    Index.js

        render() {
              console.log('in render')
             // alert("in render")
            const { module: Component } = this.state; 
            return(
              
    {Component && }
    ) } } ReactDOM.render(, document.getElementById('root'));

    FirstComponent.js

    render() {
          const { module: Component } = this.state;
        return (
          
    logo

    Edit src/App.js and save to reload.

    Learn React
    {Component && }
    ); }

提交回复
热议问题