-
Error / React-Dom.render 에러 / react-dom.development.js:86 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:Web dev/Error 2022. 4. 11. 16:32728x90반응형
깃헙페이지 때문에 테스트겸 새로 CRA로 리엑트 프로젝트를 만들었는데
이러한 에러메시지가 떴다.
이유는 리엑트 18부터는 조금 다르게 쓴다.
'react-dom.development.js:86 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:'
1. /src/index.js를 수정해주면된다.
2.import { createRoot } from 'react-dom/client'; 를 불러와 root에 담아 준다.
3.React.DOM이 아닌 root에 render 해준다.
수정전
import React from 'react'; import ReactDOM from 'react-dom'; 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();
수정 후
import React from 'react'; import { createRoot } from 'react-dom/client'; import App from './App'; import reportWebVitals from './reportWebVitals'; import create from './redux/create'; import { Provider } from 'react-redux'; const store = create(); const rootElement = document.getElementById("root"); const root = createRoot(rootElement); root.render( <React.StrictMode> <Provider store={store}> <App /> </Provider> </React.StrictMode> ); // 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();
728x90반응형'Web dev > Error' 카테고리의 다른 글