在服务器上渲染我的应用程序时,provider元素出现Invariant错误。错误是Invariant Violation: React.Children.only expected to receive a single React element child.我也收到此警告Warning: Failed prop type: Invalid prop children of type array 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;

最佳答案

<Provider>组件仅接受单个元素作为其子元素。您可以更改代码以传递元素,而不是数组:



const RouterContext = react.createElement(reactRouter.RouterContext, renderProps);
const provider = react.createElement(Provider, { store: store }, RouterContext);

关于node.js - 这是服务器代码还是应用程序代码的问题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42335372/

10-13 08:49