먼저 포스트 목록에 반영하는 작업부터 해봅시다. removePost를 구현했을 때랑 비슷한데요. usePostsupdatePost 함수를 작성해주세요. 그리고 그 함수를 usePostsEventEffect의 파라미터 객체에 포함하세요.

    hooks/usePosts.js

    (...)
    export default function usePosts(userId) {
      (...)
      const updatePost = useCallback(
        ({postId, description}) => {
          // id가 일치하는 포스트를 찾아서 description 변경
          const nextPosts = posts.map((post) =>
            post.id === postId
              ? {
                  ...post,
                  description,
                }
              : post,
          );
          setPosts(nextPosts);
        },
        [posts],
      );
    
      usePostsEventEffect({
        refresh: onRefresh,
        removePost,
        enabled: !userId || userId === user.id,
        updatePost
      });
    
      (...)
    }
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.