StrictMode
React v16.3で入った
docs
wrapして使う
code:ts
function ExampleApplication() {
return (
<React.StrictMode>
<ComponentOne />
</React.StrictMode>
);
}
Reactを変な使い方をしているとconsole.logにwarningが表示される?
production buildには影響しない
安全でないライフサイクルの特定
レガシーな文字列 ref API の使用に対する警告
非推奨な findDOMNode の使用に対する警告
意図しない副作用の検出
https://qiita.com/jkr_2255/items/b154f502d714a3b32e86
https://ja.reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects
レガシーなコンテクスト API の検出
state の再利用性を保証する
https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode
next.jsではnext.config.jsで指定する
https://ja.reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-strict-mode
v18でより厳密になっている
https://qiita.com/jkr_2255/items/b154f502d714a3b32e86
https://zenn.dev/uhyo/articles/react-18-alpha-essentials#strictmode-での-useeffect-の挙動の変化