这是服务器代码或应用程序代码的问题吗?

时间:2017-02-20 02:05:12

标签: node.js reactjs

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

1 个答案:

答案 0 :(得分:1)

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

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