use-set-state
use-set-state
객체 상태를 부분 업데이트할 수 있게 해 주는 훅이에요. 객체만 지원하고, 원시 값(primitive)이나 배열은 사용할 수 없어요.
출처: 문서
본문
사용법 (Usage)
use-set-state 훅은 객체와 함께만 동작해요. 원시 값이나 배열은 지원되지 않아요:
import { useSetState } from '@mantine/hooks';
useSetState([1, 2, 3]); // -> will not work
useSetState(1); // -> will not work
useSetState({ skills: ['JavaScript', 'TypeScript'] }); // -> works fine
정의 (Definition)
type UseSetStateCallback = (
state: Partial<T> | ((currentState: T) => Partial<T>)
) => void;
type UseSetStateReturnValue = [T, UseSetStateCallback];
function useSetState<T>(initialState: T): UseSetStateReturnValue
내보내는 타입 (Exported types)
UseSetStateCallback과 UseSetStateReturnValue 타입은 @mantine/hooks 패키지에서 내보내져요. 애플리케이션에서 임포트할 수 있어요:
import type { UseSetStateCallback, UseSetStateReturnValue } from '@mantine/hooks';