Created
May 31, 2018 18:08
-
-
Save ohansemmanuel/09db2149687c39b7b0505b0a7b4ca48f to your computer and use it in GitHub Desktop.
An unforgettable way to Learn Redux π π π https://medium.com/@ohansemmanuel/an-unforgettable-way-to-learn-redux-the-visual-guide-f36afd38c966
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
// 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