Created
April 17, 2021 05:36
-
-
Save rezwan-hossain/9325a9f54669b5e8a96a2c8d749eae09 to your computer and use it in GitHub Desktop.
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
const redux = require("redux"); | |
const createStore = redux.createStore; | |
const initialState = { | |
counter: 0, | |
}; | |
//reducer | |
const reducer = (state = initialState, action) => { | |
const { type } = action; | |
switch (type) { | |
case "ADD_COUNTER": { | |
return { | |
...state, | |
counter: +1, | |
}; | |
} | |
default: | |
return state; | |
} | |
}; | |
//Store | |
const store = createStore(reducer); | |
// Dispatching action | |
const ADD_COUNTER = { | |
type: "ADD_COUNTER", | |
}; | |
//Subcription | |
store.subscribe(() => { | |
const letestState = store.getState(); | |
console.log(letestState); | |
}); | |
store.dispatch({ type: "ADD_COUNTER" }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment