Last active
February 28, 2021 16:24
-
-
Save JaysonChiang/a2b1cba3bcad066054050efa0cbd75aa to your computer and use it in GitHub Desktop.
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
const ADD_TODO = 'add_todo'; | |
const ADD_TODO_SUCCESS = 'add_todo_success'; | |
const ADD_TODO_ERROR = 'add_todo_error'; | |
const initialState = { | |
loading: false, | |
error: null, | |
data: [], | |
} | |
const reducer = (state = initialState, action) => { | |
switch (action.type) { | |
case ADD_TODO: | |
return { loading: true, error: null, data: [] }; | |
case ADD_TODO_SUCCESS: | |
return { loading: false, error: null, data: action.payload }; | |
case ADD_TODO_ERROR: | |
return { loading: false, error: action.payload, data: [] }; | |
default: | |
return state; | |
} | |
}; | |
export default reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment