0
望着在ReactJS文檔的"Choosing the Type at Runtime" section,它看起來像下面的代碼應該工作:ReactJS無效的組件類型
class App extends Component {
constructor() {
super();
this.state = { test: <div>Test</div>};
}
render() {
const Test = this.state.test;
return <Test />;
}
}
但是,沒有渲染,並在控制檯中我看到了以下錯誤:
warning.js:36 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of `App`.
我不明白爲什麼這不起作用;請解釋。
請注意,上述測試應用程序是使用create-react-app創建的。