Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ohansemmanuel/09db2149687c39b7b0505b0a7b4ca48f to your computer and use it in GitHub Desktop.
Save ohansemmanuel/09db2149687c39b7b0505b0a7b4ca48f to your computer and use it in GitHub Desktop.
// An example of an action
const action = {
type: "WITHDRAW_MONEY",
amount: "$10,000"
}
// A basic reducer. Takes in two parameters: state, and action.
const reducer = (state, action) => {
return state;
};
// How to create a Store
import { createStore } from "redux"; //an import from the redux lib
import reducer from "./reducers"
const store = createStore(reducer);
//Never mutate the state that comes into the reducer. This is WRONG!
const reducer = (state=[], action) => {
return state.push('new value');
};
//This is RIGHT!
const reducer = (state=[], action) => {
return [...state, 'new value']
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment