Created
February 14, 2020 13:39
-
-
Save markodayan/41f817ac9048ce50888e8e5f3047576d to your computer and use it in GitHub Desktop.
Basic Reducer Functionality (Dispatching Actions sent from components)
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
// initState defined beforehand in file or wherever and import it | |
const rootReducer = (state = initState, action) => { | |
if (action.type === 'DELETE_POST') { | |
let newPosts = state.posts.filter(post => action.id !== post.id); | |
return { | |
...state, | |
posts: newPosts | |
}; | |
} | |
return state; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment