小编Mar*_*taJ的帖子

"不变违规"在服务器端使用React Server renderToString

我正在尝试使用Webpack设置一个同构服务器端呈现React应用程序,但是当我尝试使用renderToString将我的React代码转换为字符串时出现此错误:

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Run Code Online (Sandbox Code Playgroud)

当我用renderToString函数注释掉这行时,我停止得到这个错误(当然,应用程序仍然不起作用 - 我只是不再收到错误消息).

我已经尝试传递renderToString <RootApp />React.createElement(RoutingContext不是制作工厂,但这些都没有奏效.使用React.createElement导致相同的错误,并使用<RootApp />扔了一个unexpected token < error.

关于可能发生的事情的想法?

我的应用看起来像:

app.js

"use strict"

require("babel-register");
const Express = require('express');
const BodyParser = require('body-parser'); …
Run Code Online (Sandbox Code Playgroud)

node.js reactjs isomorphic-javascript server-side-rendering

5
推荐指数
1
解决办法
978
查看次数