React (2) - TypeScript ์์ setState props๋ก ๋๊ธธ ๋ Type ์ง์ ํ๋ ๋ฒ
์์ ์ปดํฌ๋ํธ์์ useState ํจ์๋ฅผ ๋๊ธธ ๋ ์๋ ์ฒ๋ผ ๊ธฐ์กด์ ํด์๋ ๊ฒ์ฒ๋ผ void๋ก ๋๊ฒผ๋๋ฐ, react ์์ ๋ ์ ์ ํ ํ์
์ ์ ๊ณตํ๊ณ ์์๋ค interface ITestProps{ setTest: () => void } SetStateAction ๊ณผ Dispatch ์ด๋ค. import React, { SetStateAction, Dispatch } from 'react' interface Props { setTest: Dispatch } ์์ ์ฝ๋์ฒ๋ผ ํ์
์ ์์ฑํ๊ฒ ๋๋ฉด ์ด๋ค ํ์
์ ๊ฐ์ ๋ฃ์ด์ผํ๋์ง ํจ์ฌ ์ฝ๊ฒ ์ ์ ์๋ค. https://newbedev.com/passing-usestate-as-props-in-typescript Passing useState as props in typ..
2022.04.04