React.Dispatch<React.SetStateAction<string>>

이유정·2023년 9월 2일
0

Typescript

목록 보기
2/5

React.Dispatch<React.SetStateAction<string>>

상위 컴포넌트에서 useState 상태 변경 함수를 넘길 때 () => void 로 넘겼었는데 정의 할 수 있는 타입이 있었다 !

interface Props{
  setIsMade: () => void
}
import React, {useState, Dispatch, SetStateAction} from 'react'; 
interface Props{
	setIsMade: Dispatch<SetStateAction<boolean>>
}

insight

set 함수를 넘길 때는 default 값에 따라
1)string 인 경우 React.Dispatch<React.SetStateAction<string>>
2)boolean 인 경우
React.Dispatch<React.SetStateAction<boolean>>

profile
팀에 기여하고, 개발자 생태계에 기여하는 엔지니어로

0개의 댓글