React.createElement的问题

时间:2016-12-03 17:00:23

标签: javascript reactjs

我正在尝试重现this教程(它已经过时了)并且在这个地方

var html = ReactDOM.renderToString(React.createElement(Router.RouterContext, renderProps));

我收到此错误:

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).

触发的错误
import createBrowserHistory from 'history/createBrowserHistory';
let history = createBrowserHistory();

ReactDOM.render(
    <Router history={history}>
        {routes}
    </Router>, 
    document.getElementById('app')
);

我是React的新手所以也许你可以帮助我?

1 个答案:

答案 0 :(得分:0)

在这些部分之后有一个更新:

October 19, 2015 Update: Previous React.renderToString now lives
in the react-dom/server package. Additionally, server-side rendering
with    React Router has changed quite a bit. See Server Rendering
Guide for more details.

您似乎需要根据“服务器渲染指南”进行设置。