action

// 액션 타입
const ADD_TODO = 'Add_todo'

// 액션 생성자
function addToDo(_todo) {
  return ({
    type: ADD_TODO,
    todo: _todo  // store에 있는 state
  })
}

reducer

// state의 초기값
const initalState = {
	count: 0
}

function reducer(state = initalState, action) {
	// action 1
	if(action.type === 'PLUS')
		return { count: state.count + 1 } // 새로운 객체 반환
	// action 2
	if(action.type === 'MINUS')
		return { count: state.count - 1 } // 새로운 객체 반환

	return state  // 기존 객체
}

// combineReducer
import { combineReducers } from 'redux'

const rootReducer = **combineReducers**({
	tomato: tomatoReducer,
	potato: potatoReducer
})

// 리듀서를 여러개로 합쳤다면, useSelector의 사용법이 달라진다.
const title = useSelector(state => state.**postReducer**.title)  // 어떤 리듀서인지 명시해야함

store

// store 객체 생성
import { createStore } from 'redux'

const store = createStore(myReducer) // store와 reducer를 연결

// state 객체 불러오기
store.getState()

// 액션을 store의 reducer에게 전달
store.dispatch(액션 생성자 함수())

// state 변경 주시하고 있기
const unsubscribe = store.subscribe(콜백 함수)

// unsubscribe 호출
unsubscribe()