Created
June 12, 2020 23:01
-
-
Save KonradSzwarc/e157525e661719a1835e11ae0819c4c1 to your computer and use it in GitHub Desktop.
Redux utility function that creates a state slice for asynchronous data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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