본문 바로가기
Framework/React

[React] ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17.

by pcm9881 2023. 8. 1.

Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://react.dev/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis

 

How to Upgrade to React 18 – React

The library for web and native user interfaces

react.dev

 

React 17 버전에서 18 버전으로 변경 했을 시 생기는 이슈 또는 18 버전에서 17 버전처럼 사용했을 시 생기는 경고입니다.

 

React 17

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById("root")
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

 

React 18

import React from 'react';
import * as ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);
reportWebVitals();

 

수정하면 더이상 경고 문구는 나오지 않습니다.

728x90

댓글