FrontEnd
[React] CRA react-app 17 버전으로 변경하기(+ts)
mingg123
2023. 3. 15. 00:27
react 18이 나온 이후 npx create-react-app을 이용하여 초기 프로젝트를 생성하게 되면
react 18버전 기준으로 프로젝트가 생성된다.
나는 SSR(server side rendering)로 진행하고 싶지 않을 경우 17로 대부분 바꾸어서 진행을 한다.
+typescript를 사용하는 경우
1. npx create-react-app my-app --template typescript
프로젝트를 세팅한다.
2. package.json 17로 변경해준다.
"react": "^17.0.2",
"react-dom": "^17.0.2",
3. index.ts
render를 react-dom을 사용하도록 변경 해준다. (18은 react-client인가 그럴 거다..)
import React from "react";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { render } from "react-dom";
const root = document.getElementById("root");
render(<App />, root);
세 번 정도 17로 변경해서 사용하길래 기억하기 위해서 작성했다.