Skip to content

Instantly share code, notes, and snippets.

@jimthedev
Created January 21, 2020 20:16
Show Gist options
  • Save jimthedev/df0183db8207aab9ab7cd12dad2b08b3 to your computer and use it in GitHub Desktop.
Save jimthedev/df0183db8207aab9ab7cd12dad2b08b3 to your computer and use it in GitHub Desktop.
state machine using reducer
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