[英]Most confusing Invariant Violation in react
考虑以下:
import React from 'react';
import ReactDOM from 'react-dom';
import Game from './game';
const game = document.getElementById('game');
if (game !== null) {
ReactDOM.render(
<React.Strict>
<Game />
</React.Strict>,
game
);
}
Game
的定义如下:
import React from 'react';
export default class Game extends React.Component {
constructor(props) {
super(props);
this.apiUrl = window.location.protocol + '//' + window.location.host + '/';
}
render() {
return (
<div>
</div>
)
}
}
我从中删除了所有内容,开始时没有太多内容,但是仍然可以在浏览器控制台中看到:
未捕获的不变违规:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。 您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入。
最后,我检查了导出和导入的正确性。 我在想什么,这应该不会使React.Strict
失败。
根据这里的文档,它应该是<React.StrictMode>
,而不是<React.Strict>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.