[英]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.