gpt4 book ai didi

reactjs - 代码分割/ react 可加载问题

转载 作者:行者123 更新时间:2023-12-03 13:25:18 24 4
gpt4 key购买 nike

我正在尝试使用react-loadable 将代码拆分引入我的应用程序。我在一个非常简单的组件上尝试过:

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

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

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

我没有看到任何明显的错误,并且我无法在该存储库中提交问题。

最佳答案

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

关于reactjs - 代码分割/ react 可加载问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47355789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com