[React] Redux 정리

한줄 간단 요약:
Redux를 사용하면 state를 바로 바꾸는 것이 아니라 action이라는 객체를 생성하여 어떤 state를 바꾸고 싶은지를 type에 명시하여 dispatch하면, 해당되는 reducer가 action.type에 따라 state를 변경한다.

combineReducer()
Reducer의 인자로 넘어오는 state는 현재의 state, action은 dispatcher가 보낸 action 객체이다.

combineReducer()는 state에서 key와 이름이 같은 property를 argument로하여 호출해준다.
import { combineReducers } from 'redux'
const todoApp = combineReducers({
visibilityFilter,
todos
})
export default todoApp
위의 코드는 아래와 같다:
export default function todoApp(state = {}, action) {
return {
visibilityFilter: visibilityFilter(state.visibilityFilter, action),
todos: todos(state.todos, action)
}
}


custom하게 사용하고 싶다면:
function reducer(state = {}, action) {
return {
a: doSomethingWithA(state.a, action),
b: processB(state.b, action),
c: c(state.c, action)
}
}






댓글

이 블로그의 인기 게시물

[Django 공식문서 번역] REST Framework - Viewset and Router

[Django REST Framework] create() vs perform_create()

Intel Open WebRTC Toolkit(OWT) Media server 설치하는법