const reducer = (state = [], action) => {
switch(action.type){
case 'ADD_TODO': return [...state, {text:action.text, id:Date.now()}]
case 'DELETE_TODO': return []
default: return state;
}
};
const store = createStore(reducer)
store.subscribe()
const onSubmit = e => {
e.preventDefault();
const toDo = input.value;
input.value = "";
store.dispatch({type:"ADD_TODO", text: toDo})
};
form.addEventListener('submit', onSubmit)
여기서 store.dispatch() 인자로 type 보내는 건 알았는데, 한개를 더 보내더라구요
그래서 action.type이 일치할때 [{text:action.text}]를 return 하던데
text(두번째 인자)는 어떤 걸 의미하는지 모르겠습니다
디스패치로 보낼때 text상태를 todo로 보낸다 했잖아 그게 action객체에 text 프로퍼티에 todo로 담겨있는거임.
왠지 우리 팀원 스멜 나는데 힘내라.
감사합니다 팀장님^^7