Created
January 21, 2020 20:16
-
-
Save jimthedev/df0183db8207aab9ab7cd12dad2b08b3 to your computer and use it in GitHub Desktop.
state machine using reducer
This file contains 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
const reducer = (state, action) => { | |
if (state.status === 'idle') { | |
if (action.type === 'fetch') { | |
return { | |
status: 'fetching' | |
} | |
} | |
} | |
if (state.status === 'fetching') { | |
if (action.type === 'resolve') { | |
return { | |
status: 'success' | |
} | |
} | |
if (action.type === 'error') { | |
return { | |
status: 'failed' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment