Skip to content

Instantly share code, notes, and snippets.

View alirezaseif28's full-sized avatar
🏢
Working from home

Alireza alirezaseif28

🏢
Working from home
View GitHub Profile
@alirezaseif28
alirezaseif28 / useAsyncReducer
Created June 30, 2023 13:53
useReducer in React is Async
import React, { useEffect, useMemo, useReducer } from "react";
export type Reducer<State, Action> = (state: State, action: Action) => State;
export type AsyncReducer<State, Action> = (
state: State,
action: Action
) => { state: State; effects: Array<Lazy<Promise<Array<Action>>>> };
export function useAsyncReducer<State, Action>(