인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

herman's profile image
herman

asked

Practical React Programming

Asynchronous action processing using redux-saga2

선생님 질문있습니다 !

Written on

·

215

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 사용이 가능한건가요 ???
reduxreact

Answer 1

1

landvibe님의 프로필 이미지
landvibe
Instructor

안녕하세요
setValueReducer 함수가 입력된 형태이므로 아래 코드1/2는 같습니다

코드1:
[types.SET_VALUE]: setValueReducer

코드2:
[types.SET_VALUE]: (state, action) => (state[action.key] = action.value)

herman's profile image
herman

asked

Ask a question