mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
More DRY code. Also move non-hooks to separate directories. BREAKING CHANGE: all `create*` factories been moved to `factory` subdirectory and in case direct import should be imported like `react-use/esm/factory/createBreakpoint` BREAKING CHANGE: `comps` directory renamed to `component`
19 lines
908 B
TypeScript
19 lines
908 B
TypeScript
export type IHookStateInitialSetter<S> = () => S;
|
|
export type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
|
|
|
|
export type IHookStateSetter<S> = ((prevState: S) => S) | (() => S);
|
|
export type IHookStateSetAction<S> = S | IHookStateSetter<S>;
|
|
|
|
export type IHookStateResolvable<S> = S | IHookStateInitialSetter<S> | IHookStateSetter<S>;
|
|
|
|
export function resolveHookState<S>(nextState: IHookStateInitAction<S>): S;
|
|
export function resolveHookState<S, C extends S>(nextState: IHookStateSetAction<S>, currentState?: C): S;
|
|
export function resolveHookState<S, C extends S>(nextState: IHookStateResolvable<S>, currentState?: C): S;
|
|
export function resolveHookState<S, C extends S>(nextState: IHookStateResolvable<S>, currentState?: C): S {
|
|
if (typeof nextState === 'function') {
|
|
return nextState.length ? (nextState as Function)(currentState) : (nextState as Function)();
|
|
}
|
|
|
|
return nextState;
|
|
}
|