Javascript ReactDOMServer.renderToString不是函数
我在服务器上渲染react组件,并在转到路由时获取错误消息:Javascript ReactDOMServer.renderToString不是函数,javascript,node.js,reactjs,react-server,Javascript,Node.js,Reactjs,React Server,我在服务器上渲染react组件,并在转到路由时获取错误消息: const renderToString=ReactDOMServer.renderToString const fac=React.createFactory(React.createClass({ render:function(){ 返回( ) }})) const appHtml=renderToString(fac()) 我建议你这样写: const ReactDOMServer = require('react-dom/
const renderToString=ReactDOMServer.renderToString
const fac=React.createFactory(React.createClass({
render:function(){
返回(
)
}}))
const appHtml=renderToString(fac())
我建议你这样写:
const ReactDOMServer = require('react-dom/server');
const appHtml = ReactDOMServer.renderToStaticMarkup (
<Provider store={store}>
<StaticRouter location={location} context={routeContext}>
<App />
</StaticRouter>
</Provider>
);
const ReactDOMServer=require('react-dom/server');
const appHtml=ReactDOMServer.renderToStaticMarkup(
);
我希望它能帮助您。您是否以某种方式导入/需要
renderToString
呢?是的,renderToString=ReactDOMServer.rendertomstring您是否有类似于从“react dom/server”导入ReactDOMServer的东西。在.js文件的顶部行?如果我console.log ReactDOMServer.renderToString它返回函数OK,如果您尝试像这样调用renderToString
ReactDOMServer.renderToString,会怎么样?谢谢!!我一直在寻找这个确切的功能。
const ReactDOMServer = require('react-dom/server');
const appHtml = ReactDOMServer.renderToStaticMarkup (
<Provider store={store}>
<StaticRouter location={location} context={routeContext}>
<App />
</StaticRouter>
</Provider>
);