자, 그럼 이제 todos 모듈의 액션 생성 함수를 다음과 같이 새로 작성해 주세요.

    modules/todos.js

    import { createAction } from 'redux-actions';
    
    const CHANGE_INPUT = 'todos/CHANGE_INPUT'; // 인풋 값을 변경함
    const INSERT = 'todos/INSERT'; // 새로운 todo를 등록함
    const TOGGLE = 'todos/TOGGLE'; // todo를 체크/체크 해제함
    const REMOVE = 'todos/REMOVE'; // todo를 제거함
    
    export const changeInput = createAction(CHANGE_INPUT, input => input);
    
    let id = 3; // insert 호출될 때마다 1 더해집니다.
    export const insert = createAction(INSERT, text => ({
      id: id++,
      text,
      done: false,
    }));
    
    export const toggle = createAction(TOGGLE, id => id);
    export const remove = createAction(REMOVE, id => id);
    
    (...)

     

    insert의 경우 todo 객체를 액션 객체 안에 넣어 주어야 하기 때문에 두 번째 파라미터에 text를 넣으면 todo 객체가 반환되는 함수를 넣어 주었습니다.

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.