Search code examples
reactjsreact-loadable

react-loadable callback when load done?


Is there any callback for react-loadable when it loaded the component? I can not find any info in the document of react-loadable.


Solution

  • You may make use of its loader property or render method:

    Loadable({
      loader: () =>
        import("./components/Bar").then(Bar => {
          console.log("loaded"); // Put your callback here
          return Bar;
        }),
    });
    

    or,

    Loadable({
      loader: () => import("./components/Bar"),
      render(loaded, props) {
        console.log("loaded"); // Put your callback here
        let Component = loaded.default;
        return <Component {...props} />;
      },
    });