在服务器上渲染我的应用程序时,我得到了提供程序元素的不变错误。错误是Invariant Violation: React.Children.only expected to receive a single React element child.
我也收到此警告Warning: Failed prop type: Invalid prop
子of type
数组supplied to Provider, expected a single ReactElement. in Provider
const store = createStoreWithMiddleware(reducers);
const provider = react.createElement(Provider, { store: store }, RouterContext);
const ReactApp = renderToString(provider);
const reactRouter = require('react-router');
const RouterContext = reactRouter.RouterContext;
答案 0 :(得分:1)
<Provider>
组件只接受一个元素作为其子元素。您可以更改代码以传递元素,而不是数组:
const RouterContext = react.createElement(reactRouter.RouterContext, renderProps);
const provider = react.createElement(Provider, { store: store }, RouterContext);