Skip to content

Instantly share code, notes, and snippets.

@KonradSzwarc
Created June 12, 2020 23:01
Show Gist options
  • Save KonradSzwarc/e157525e661719a1835e11ae0819c4c1 to your computer and use it in GitHub Desktop.
Save KonradSzwarc/e157525e661719a1835e11ae0819c4c1 to your computer and use it in GitHub Desktop.
Redux utility function that creates a state slice for asynchronous data.
export type AsyncState<T> = {
status: 'idle' | 'loading' | 'success' | 'failure';
data: T;
error: string | null;
};
export const createAsyncState = <T>(initialData: T): AsyncState<T> => ({
status: 'idle',
data: initialData,
error: null,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment