admin管理员组文章数量:1353587
I render react ponent on server and when go to route get error message:
const renderToString = ReactDOMServer.renderToString
const fac = React.createFactory(React.createClass({
render: function() {
return (
<Provider store={store}>
<StaticRouter location={location} context={routeContext}>
<App />
</StaticRouter>
</Provider>
)
}}))
const appHtml = renderToString(fac())
I render react ponent on server and when go to route get error message:
const renderToString = ReactDOMServer.renderToString
const fac = React.createFactory(React.createClass({
render: function() {
return (
<Provider store={store}>
<StaticRouter location={location} context={routeContext}>
<App />
</StaticRouter>
</Provider>
)
}}))
const appHtml = renderToString(fac())
Share
Improve this question
edited Mar 22, 2017 at 13:57
Khotey Vitaliy
asked Mar 22, 2017 at 13:51
Khotey VitaliyKhotey Vitaliy
5191 gold badge6 silver badges19 bronze badges
6
-
1
Do you import/require
renderToString
somehow? – Dan Cantir Commented Mar 22, 2017 at 13:55 - Yes, renderToString = ReactDOMServer.renderToString – Khotey Vitaliy Commented Mar 22, 2017 at 13:56
-
Do you have something like
import ReactDOMServer from 'react-dom/server'.
at the top lines of your .js file? – Dan Cantir Commented Mar 22, 2017 at 13:58 - If I console.log ReactDOMServer.renderToString it return function – Khotey Vitaliy Commented Mar 22, 2017 at 13:59
-
Ok, and what if you try to call
renderToString
like thisReactDOMServer.renderToString
? – Dan Cantir Commented Mar 22, 2017 at 14:00
1 Answer
Reset to default 8I suggest you write it like this:
const ReactDOMServer = require('react-dom/server');
const appHtml = ReactDOMServer.renderToStaticMarkup (
<Provider store={store}>
<StaticRouter location={location} context={routeContext}>
<App />
</StaticRouter>
</Provider>
);
I hope it helps you.
本文标签: javascriptReactDOMServerrenderToString is not a functionStack Overflow
版权声明:本文标题:javascript - ReactDOMServer.renderToString is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743934944a2564501.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论