Created
July 26, 2019 08:39
-
-
Save ppraksa/ba0613b5b1a051bff0587e62bbb8637c to your computer and use it in GitHub Desktop.
some boilerplate
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 asyncReducerFactory = (name) => { | |
return (state = { data: null, isLoading: false, error: null }, action) => { | |
switch (action.type) { | |
case `FETCH_${name}_STARTED`: | |
return { data: null, isLoading: true, error: null }; | |
case `FETCH_${name}_SUCCESS`: | |
return { data: action.payload, isLoading: false, error: null }; | |
case `FETCH_${name}_ERROR`: | |
return { data: null, isLoading: false, error: action.payload }; | |
default: | |
return state; | |
} | |
}; | |
}; |
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 data = asyncReducerFactory('DATA'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment