React/error
[React] ReactDOM.render 오류 :ReactDOM.render is no longer supported in React 18..
07a
2023. 2. 1. 11:51
오류:
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. |
현재 리액트를 사용하면 콘솔창에 "경고: ReactDOM.render는 React 18에서 더 이상 지원되지 않습니다. 대신 createRoot를 사용하세요. 새 API로 전환할 때까지 앱은 React 17을 실행하는 것처럼 작동합니다.
원인: CRA 를 통해 만들지 않아 index.jsx 코드 작성시 잘못된 코드로 인해 root 설정에 오류가 있었다.
ReactDOM.render를 리액트 v18부터 사용하지 않기 때문에 경고메세지가 나타났음.
해결: 아래 코드 삽입
src/index.jsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);