TypeScript2 [React] React Router - Link 동적 패스 지정 07.23.2023 1. 기본 Link 사용법 App.tsx에 먼저 패스 등록을 해줘야 한다. import { BrowserRouter, Route, Routes } from 'react-router-dom'; import Main from 'pages/Main'; function App(): JSX.Element { return ( ); } export default App; 이 다음 해당 컴포넌트에서 이와 같은 코드를 써주면 된다. import { Link } from 'react-router-dom'; function Example(): JSX.Element { return ( Main ); } export default Example; 2. 컴포넌트에 Link 적용하기 Link는 a태그로 렌더링된.. 2023. 7. 23. React와 TypeScript 초기세팅 07.19.2023 0. Background React.js를 쓸 때 TypeScript가 이제는 거의 디폴트가 되었다. 그래서 두 개를 같이 쓸 때 필요한 초기세팅 프로세스를 간단하게 적어보았다. 1. create-react-app을 사용한다면 (If using create-react-app) 간단하게 create-react-app 명령어로 시작할 수 있다. $npx create-react-app "your target directory" -template typescript 2. react-react-app을 사용하지 않는다면 (If not using create-react-app) $npm i -g typescript 이 명령어의 경우, 로컬에서 다른프로젝트를 이용하여 이미 글로벌로 타입스크립트를 .. 2023. 7. 19. 이전 1 다음