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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743934945a4532467.html
评论列表(0条)