Skip to content

Instantly share code, notes, and snippets.

@rezwan-hossain
Created April 17, 2021 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezwan-hossain/9325a9f54669b5e8a96a2c8d749eae09 to your computer and use it in GitHub Desktop.
Save rezwan-hossain/9325a9f54669b5e8a96a2c8d749eae09 to your computer and use it in GitHub Desktop.
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