Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@kv/react-hooks / lib / hooks / setState.d.ts
Size: Mime:
import { SetStateAction } from 'react';
export declare type SetStateFp<A> = (a: SetStateAction<A>) => A;
/**
 * The `setState` function returned by `useState` always returns `undefined`,
 * which means you can't compose `setState` with other functions. This custom
 * hook returns a tapped version of `setState` as the setter that returns the
 * same value that was passed to it (i.e. `x => { setState(x); return x; }`)
 *
 * @usage
 * ```jsx
 * const [user, setUser] = useStateFp(initialUserState);
 * const updateUser = useCallback(
 *   newUserData => pipe(
 *     merge(user),
 *     setUser,
 *     displayToastWithUserData,
 *   )(newUserData),
 *   [setState]
 * );
 * ```
 */
export declare const useStateFp: <T>(initialState: T) => [T, SetStateFp<T>];
export declare const useStateDebounced: <T>(waitAmount: number, initialState: T) => [T, (newState: T) => void];