-
[React] TypeScripts Form, 패키지 or 라이브러리 typeScripts(Definitely Typed)IT/React 2022. 6. 10. 16:20
기존 React.js 에서는 함수를 생성하고 evnet.target을 이용할때
button에 들어가던 div에 들어가던 문제가 없다
문제는 없지만 렌더링이 되지 않거나 코드가 실행되지 않는 경우가 있어서 문제를 해결해야할 경우 코드 전체를 뒤집어야하는 상황이 발생할 수 있다.
그 에따라 typeScripts 에서
const onSubmit = (event) => { ... } const onSubmit = (event: React.FormEvent<HTMLFormElement>) => { ... }event에 어떠한 evnet를 사용할껀지 타입을 설정해주고 Form Element 에서 사용될 코드가 잘못 되었다면
TypeScript에서 먼저 에러를 발생시켜 코드 실행을 더욱 안전하게 해줄 수 있다
해당 공식문서에서 컴포넌트에 맞는 이벤트들을 찾아볼 수 있음Definitely Typed
npm i --save-dev @types/styled-components 등npm i --save-dev @types/ 를 사용해서 react-query 나 다른 라이브러리를 type scripts 라고 알아들을 수 있도록 install을 할 수 있다https://github.com/DefinitelyTyped/DefinitelyTyped 해당 깃허브 레포에서찾아볼 수 있지만 숨김처리되어있는게 너무나 많기 때문에GitHub - DefinitelyTyped/DefinitelyTyped: The repository for high quality TypeScript type definitions.
The repository for high quality TypeScript type definitions. - GitHub - DefinitelyTyped/DefinitelyTyped: The repository for high quality TypeScript type definitions.
github.com
일단 내가 필요한 패키지를 install 해보는 방법을 추천한다.'IT > React' 카테고리의 다른 글
[React] 정신나가도록 좋은 react-hook-form 기능들 + typeScript (0) 2022.06.12 [React] state management section ( Recoil 편 ) (0) 2022.06.12 [React] CSS Gallery 의 React화 일지 - 4 (06.05 ~ 06.10) (0) 2022.06.10 [React] styled-components interface, optional props, Type State (typescripts) (0) 2022.06.09 [React] styled-components 간단한 다크모드 만들기 (0) 2022.06.08