Inflearn Community Q&A
선생님 질문있습니다 !
Written on
·
222
0
const reducer = createReducer(init, {
[types.ADD]: (state, action) => state.timelines.push(action.timeline)
, [types.REMOVE]: (state, action) => state.timelines = state.timelines.filter(timeline => (
timeline.id !== action.timeline.id
))
, [types.EDIT]: (state, action) => {
const index = state.timelines.findIndex(timeline =>
timeline.id === action.timeline.id);
if (index >= 0) {
state.timelines[index] = action.timelines;
}
},
[types.INCREASE_NEXT_PAGE]: (state, action) => (state.nextPage += 1),
[types.ADD_LIKE]: (state, action) => {
const timeline = state.timelines.find(
item => item.id === action.timelineId
);
if (timeline) {
timeline.likes += action.value;
}
},
[types.SET_LOADING]: (state, action) => (state.isLoading = action.isLoading),
[types.SET_VALUE]: setValueReducer
});
export default reducer;
다른곳에서는 (state,action) 2개를 적어줬는데
setValueReducer 에서는 단순 함수만 호출해주었는데도
setValueReducer(state,action) 이렇게
state와 action 사용이 가능한건가요 ???
state와 action 사용이 가능한건가요 ???
reduxreact
Answer 1
1
landvibe
Instructor
안녕하세요
setValueReducer 함수가 입력된 형태이므로 아래 코드1/2는 같습니다
코드1:
[types.SET_VALUE]: setValueReducer
코드2:
[types.SET_VALUE]: (state, action) => (state[action.key] = action.value)




