UNPKG

rooks

Version:

Essential React custom hooks ⚓ to super charge your components!

30 lines 1.25 kB
import { type DependencyList } from "react"; declare type Effect<T> = (shouldContinueEffect: () => boolean) => Promise<T>; declare type CleanupFunction<T> = (result: T | void) => void; /** * A version of useEffect that accepts an async function * * @param {Effect<T>} effect Async function that can return a cleanup function and takes in an AbortSignal * @param {DependencyList} deps If present, effect will only activate if the values in the list change * @param {CleanupFunction} cleanup The destroy/cleanup function. Will be called with previous result if it exists. * @see https://react-hooks.org/docs/useAsyncEffect * @example * ```jsx * useAsyncEffect( async (shouldContinueEffect) => { const data1 = await fetchData1(arg1, arg2); if(shouldContinueEffect()) { const data2 = await fetchData2(arg1, arg2); } ... }, [arg1, arg2], (previousResult) => { // ... do something with previousResult ... } ); * ``` */ declare function useAsyncEffect<T>(effect: Effect<T>, deps: DependencyList, cleanup?: CleanupFunction<T>): void; export { useAsyncEffect }; //# sourceMappingURL=useAsyncEffect.d.ts.map