import './contrib/abortcontroller-polyfill-only'; import { Dispatch, Reducer, ReducerAction, ReducerState } from 'react'; export declare type AsyncActionHandlers, AsyncAction extends { type: string; }> = { [T in AsyncAction['type']]: AsyncAction extends infer A ? A extends { type: T; } ? (s: { dispatch: Dispatch>; getState: () => ReducerState; signal: AbortSignal; }) => (a: A) => Promise : never : never; }; export declare function useReducerAsync, I, AsyncAction extends { type: string; }, ExportAction extends AsyncAction | ReducerAction = AsyncAction | ReducerAction>(reducer: R, initializerArg: I, initializer: (arg: I) => ReducerState, asyncActionHandlers: AsyncActionHandlers): [ReducerState, Dispatch]; /** * useReducer with async actions * @example * import { useReducerAsync } from 'use-reducer-async'; * * const asyncActionHandlers = { * SLEEP: ({ dispatch, getState, signal }) => async (action) => { * dispatch({ type: 'START_SLEEP' }); * await new Promise(r => setTimeout(r, action.ms)); * dispatch({ type: 'END_SLEEP' }); * }, * FETCH: ({ dispatch, getState, signal }) => async (action) => { * dispatch({ type: 'START_FETCH' }); * try { * const response = await fetch(action.url); * const data = await response.json(); * dispatch({ type: 'FINISH_FETCH', data }); * } catch (error) { * dispatch({ type: 'ERROR_FETCH', error }); * } * }, * }; * const [state, dispatch] = useReducerAsync(reducer, initialState, asyncActionHandlers); */ export declare function useReducerAsync, AsyncAction extends { type: string; }, ExportAction extends AsyncAction | ReducerAction = AsyncAction | ReducerAction>(reducer: R, initialState: ReducerState, asyncActionHandlers: AsyncActionHandlers): [ReducerState, Dispatch];