代码拆分/反应可加载问题

Ste*_*che 7 reactjs code-splitting react-loadable

我正在尝试使用react-loadable将代码拆分到我的应用程序中.我在一个非常简单的组件上尝试了它:

const LoadableComponent = Loadable({
    loader: () => import('components/Shared/Logo/Logo'),
    loading: <div>loading</div>,
});
Run Code Online (Sandbox Code Playgroud)

但是,当呈现此组件时,我收到以下错误:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

Check the render method of `LoadableComponent`.
    in LoadableComponent (created by AppHeader)
    in div (created by AppHeader)
    in AppHeader (created by PlainChatApp)
    in div (created by PlainChatApp)
    in PlainChatApp (created by DragDropContext(PlainChatApp))
    in DragDropContext(PlainChatApp) (created by Connect(DragDropContext(PlainChatApp)))
    in Connect(DragDropContext(PlainChatApp))
    in Provider
    in AppContainer
    in ErrorBoundary

The above error occurred in the <LoadableComponent> component:
    in LoadableComponent (created by AppHeader)
    in div (created by AppHeader)
    in AppHeader (created by PlainChatApp)
    in div (created by PlainChatApp)
    in PlainChatApp (created by DragDropContext(PlainChatApp))
    in DragDropContext(PlainChatApp) (created by Connect(DragDropContext(PlainChatApp)))
    in Connect(DragDropContext(PlainChatApp))
    in Provider
    in AppContainer
    in ErrorBoundary
Run Code Online (Sandbox Code Playgroud)

我没有看到任何明显的错误,我也无法在该回购中提出问题.

Ste*_*che 22

事实证明,您需要将组件传递给loading选项而不是JSX.文档清楚地说明了这一点,我只是错过了它.

  • 有关更多详细信息:loading:()=> <div> loading </ div> (2认同)