React Reducer

2021. 7. 31. 16:08React

Action을 받아서 새로운 State를 return

 

 

1
2
3
function reducer(previousState, action) {
  return newState;
}
cs

 

1
2
3
4
5
6
7
8
9
10
11
12
13
import { ADD_TODO } from './actions';
 
const initialState = [];
 
function todoApp(previousState = initialState, action) {
 
  if(action.type === ADD_TODO) {
    return [...previousState, action.todo];
  }
 
  //push 사용 안됨.
  return previousState;
}
cs

'React' 카테고리의 다른 글

Redux Store  (0) 2021.07.31
Redux Action  (0) 2021.07.31
React Reconciliation  (0) 2021.07.30
react-router-dom Redirect  (0) 2021.07.27
react-router-dom에서 페이지 이동시 Link component 사용  (0) 2021.07.27