Khotey Vitaliy
Khotey Vitaliy

Reputation: 519

ReactDOMServer.renderToString is not a function

I render react component on server and when go to route get error message:

enter image description here

  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())

Upvotes: 4

Views: 9257

Answers (1)

alireza
alireza

Reputation: 546

I 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.

Upvotes: 8

Related Questions