[Redux] Vanilla JavaScript에 Redux 적용하기(subscribe) #2


[Redux] Vanilla JavaScript에 Redux 적용하기(subscribe) #2

import { legacy_createStore as createStore } from "redux"; //state가 없으면 default로 0으로 호출한다. const reducer = (state = 0, action) => { console.log(state, action); if (action.type === "ADD") { return state + 1; } else if (action.type === "MINUS") { return state - 1; } else { return state; } }; const store = createStore(reducer); add.addEventListener("click", () => { store.dispatch({ type: "ADD" }); }); minus.addEventListener("click", () => { store.dispatch({ type: "MINUS" }); }); 여기까지 진도를 나왔었고, 아랫부분...


#action #createstore #dispatch #redux #subscribe

원문링크 : [Redux] Vanilla JavaScript에 Redux 적용하기(subscribe) #2