Skip to content

Instantly share code, notes, and snippets.

@markodayan
Created February 14, 2020 13:39
Show Gist options
  • Save markodayan/41f817ac9048ce50888e8e5f3047576d to your computer and use it in GitHub Desktop.
Save markodayan/41f817ac9048ce50888e8e5f3047576d to your computer and use it in GitHub Desktop.
Basic Reducer Functionality (Dispatching Actions sent from components)
// 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