LoginSignup
11
7

More than 1 year has passed since last update.

React18で環境構築したが、エラーが出たので、React17へダウングレードした話

Last updated at Posted at 2022-04-09

備忘録として残します。
また、同じ事で詰まった方へ向けて、参考になれば幸いです。

React 18が、2022年3月29日にリリースされました。
React 18 is now available on npm!

要約

React18にて環境構築をすると、下記エラーが発生。

Warning: ReactDOM.render is no longer supported in React18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React17.

色々情報収集すると、周辺ライブラリやらまだ対応していない事から、
React17へダウングレードを実施したので、その方法を共有します。

手順

1)create-react-appで環境構築

npx create-react-app . --template typescript

React18(Typescriptベース)のテンプレートを作成する

2)ブラウザで確認(npm run start)するとエラーが表示される

Warning: ReactDOM.render is no longer supported in React18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React17.

ふむふむ。そうなのか。
そもそもReact18が先週リリースされていたとは。。

色々調べてみると、まだリリースしたばかりで対応していないライブラリやら多いようで、
このままプロジェクトを進めるのは避けようと判断。

3)React17へダウングレード

npm install -save react@17.0.2 react-dom@17.0.2

この状態でブラウザで確認してみると、2)のエラーは出なかった。
ほっ。。

所感

手順をサラッと書いてますが、
実は、React17へのダウングレードの方法が分からず、結構調べました。。

現時点('22/4/7)では、create-react-app を実行すると、
自動的にReact18がインストールされるので、エラーが出ると思います。
しばらくは、React17で様子見していた方がよさそう。

今後も備忘録として、色々アウトプットしていきたいと思います。
(React.js, TypeScript, AWSメイン)

11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7