웹_프론트엔드/React

[React.ts] props로 setState 넘길 때 타입 지정하는 방법

young 2022. 12. 19. 11:10
반응형

Dispatch<setStateAction<타입>> 형태로 타입을 지정한다.

import { Dispatch, SetStateAction, useState } from "react";

interface IExample {
    state: boolean;
    setState: Dispatch<SetStateAction<boolean>>;
}

const [state, setState] = useState(false);
반응형