Skip to content

Conversation

@cdm1263
Copy link
Contributor

@cdm1263 cdm1263 commented Aug 30, 2024

onMutate의 argument가 생략되어 있어 추가했습니다.

사용자 경험(UX)을 올려주는 Optimistic Updates(낙관적 업데이트)

onMutate: async (newHero) => { ... } 의 형태로 argument를 함수로 넘겨주어야 합니다.

onMutate: async () => {
  await queryClient.cancelQueries(["super-heroes"]);

  const previousHeroData = queryClient.getQueryData(["super-heroes"]);

  queryClient.setQueryData(["super-heroes"], (oldData: any) => {
    return {
      ...oldData,
      data: [...oldData.data, { ...newHero, id: oldData?.data?.length + 1 }],
    };
  });

  return { previousHeroData };
},

newHero를 받아오는 argument가 빠져 있어 수정하였습니다.

// mutate를 통해 전달받은 newHero를 onMutate 의 함수 argument로 받아야 함.
onMutate: async (newHero: any) => {
  await queryClient.cancelQueries(["super-heroes"]);

  const previousHeroData = queryClient.getQueryData(["super-heroes"]);

  queryClient.setQueryData(["super-heroes"], (oldData: any) => {
    return {
      ...oldData,
      data: [...oldData.data, { ...newHero, id: oldData?.data?.length + 1 }],
    };
  });

  return { previousHeroData };
},

`onMutate`의 argument가 생략되어 있어 추가했습니다.
Copy link
Owner

@ssi02014 ssi02014 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 작업을 진행해주셔서 감사합니다 :)

@ssi02014 ssi02014 merged commit 8dd42a9 into ssi02014:main Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants