27.1.2 수정 버튼 클릭 시 글쓰기 페이지로 이동하기

    이제 수정 버튼을 클릭하면 글쓰기 페이지로 이동하고, 현재 보고 있는 포스트가 나타나게 해 봅시다. 우선 write 리덕스 모듈에 SET_ORIGINAL_POST라는 액션을 만드세요. 이 액션은 현재 보고 있는 포스트 정보를 write 모듈에서 관리하는 상태에 넣습니다.

    modules/write.js

    (...)
    const SET_ORIGINAL_POST = 'write/SET_ORIGINAL_POST';
    
    (...)
    export const setOriginalPost = createAction(SET_ORIGINAL_POST, post => post);
    
    // 사가 생성
    (...)
    
    const initialState = {
      title: '',
      body: '',
      tags: [],
      post: null,
      postError: null,
      originalPostId: null,
    };
    
    const write = handleActions(
      {
        (...)
        [SET_ORIGINAL_POST]: (state, { payload: post }) => ({
          ...state,
          title: post.title,
          body: post.body,
          tags: post.tags,
          originalPostId: post._id,
        }),
      },
      initialState,
    );
    
    export default write;

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