UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

17 lines (16 loc) 842 B
/** * @name useSetState * @description - Hook that manages an object state, merging updates like `this.setState` in class components. * * @template T The type of the state object. * @param {T | (() => T)} initialState The initial state object or a function that returns it. * @returns {[T, (patch: Partial<T> | ((prevState: T) => Partial<T>)) => void]} A tuple containing the current state object and a function to merge updates into it. * * @example * const [state, setState] = useSetState({ count: 0, name: 'Default' }); * // Update only count * setState({ count: 1 }); * // Update name using a function * setState(prevState => ({ name: prevState.name.toUpperCase() })); */ export declare const useSetState: <T extends object>(initialState: T | (() => T)) => [T, (patch: Partial<T> | ((prevState: T) => Partial<T>)) => void];