Open WONILLISM opened 2 years ago
typescript에서 state를 관리해보자.
typescript의 장점은 state관리에 있어서 어떤 타입의 값을 초기화를 한다면 다른 타입의 값이 들어왔을 때 잘못된값이라고 에러를 출력해준다. 드문 경우이긴 하지만 초기 값이 아닌 값을 넣고 싶은 경우에는 const [value, setValue] = useState<number|string>(0);과 같이 명시해서 사용할 수 있다.
const [value, setValue] = useState<number|string>(0);
typescript에서 state를 관리해보자.