{
type: 'TOGGLE_VALUE'
}
예시)
{
type: 'ADD_TODO',
data: {
id: 1,
text: '리덕스 배우기'
}
}
{
type: 'CHANGE_INPUT',
text: '안녕하세요'
}
function addTodo(data) {
return {
type: 'ADD_TODO',
data
};
}
// 화살표 함수로도 만들 수 있음
const changeInput = text => ({
type: 'CHANGE_INPUT',
text
}) ;
const initialState = {
counter: 1
};
function reducer(state = initialState, action) {
switch (action.type) {
case INCREMENT:
return {
counter: state.counter + 1
};
default:
return state;
}
}
const listener = () => {
console.log('상태가 업데이트됨');
}
const unsubscribe = store.subscribe(listener);
unsubscribe();