귀농 전까지 쓰는 개발 일지

<Error> 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. 본문

공부/React

<Error> 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.

한호잉 2023. 7. 18. 17:30

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.

 

 

원인

React 18에서 변경된 API 사용에 관한 건.

ReactDOM.render 대신 createRoot 함수를 사용해야 함, 새로운 API로 전환하지 않으면 앱은 React 17처럼 동작함

 

해결

1. ReactDOM.rendercreateRoot로 변경

 

기존 코드 

import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(<App />, document.getElementById('root'));

 

변경 후 코드

import React from 'react';
import { createRoot } from 'react-dom';

createRoot(document.getElementById('root')).render(<App />);

 

'공부 > React' 카테고리의 다른 글

[React] 실전형 리액트 Hooks 10  (0) 2023.07.30
<React> Emoji  (0) 2022.03.17
[React] Component / Props / State  (0) 2022.01.17
[React] html문서 -> React문서로 변환  (0) 2022.01.17
[React] 프로젝트 생성 / 배포  (0) 2022.01.17