React: dynamic import jsx

后端 未结 3 681
鱼传尺愫
鱼传尺愫 2021-02-04 18:55

This question related to dynamically importing JSX files into React.

Basically we have one main component that dynamically renders other components based on a structure

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 19:44

    What about having a components/index.js with contents:

    export CompA from "./comp_a";
    export CompB from "./comp_b";
    

    Then you do:

    import * as Components from "./components"
    

    then you would use as:

    
    
    ...
    

    Hope this helps.

    I doubt you can load anything when sending path through component props, loading of the file should then happen inside the React component lifecycle methods which is not something I would recommend.

提交回复
热议问题