简体   繁体   English

ReactDOMServer.renderToString不是函数

[英]ReactDOMServer.renderToString is not a function

I render react component on server and when go to route get error message: 我在服务器上渲染react组件,当转到路由获取错误消息:

在此输入图像描述

  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 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. 我希望它对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 onClick处理程序没有注册ReactDOMServer.renderToString - onClick handler not registering with ReactDOMServer.renderToString 在 Typescript 中使用 ReactDomServer.renderToString 的正确方法是什么 - What's the proper way of using ReactDomServer.renderToString with Typescript JavaScript:如何使用 ReactDOMServer.renderToString 格式化 str.replace,使用捕获的元素作为道具 - JavaScript: How to format a str.replace with ReactDOMServer.renderToString, using a captured element as a prop 使用 ReactDOMServer.renderToString 将 gatsby-image 注入从 markdown 创建的 html - Injecting gatsby-image into html created from markdown using ReactDOMServer.renderToString 为什么 ReactDOMServer 和 ReactDOM 给出“root.hydrate 不是函数”错误 - Why do ReactDOMServer and ReactDOM give the "root.hydrate is not a function" error ReactDOMServer未定义 - ReactDOMServer is not defined 角2等效的react renderToString - angular 2 equivalent of react renderToString 反应renderToString不渲染js - React renderToString not rendering js React renderToString组件单元测试 - React renderToString component unit testing ReactDOM.renderToString sessionStorage未定义,窗口未定义 - ReactDOM.renderToString sessionStorage is not defined, window is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM