Skip to content

Commit

Permalink
fix: modify onMutate
Browse files Browse the repository at this point in the history
  • Loading branch information
louisewang1 committed May 10, 2022
1 parent f2a3355 commit 849e442
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/mutations/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ export default (queryClient: QueryClient, queryConfig: QueryClientConfig) => {
queryClient.setMutationDefaults(MUTATION_KEYS.ADD_FAVORITE_ITEM, {
mutationFn: (payload) => {
const {memberId, itemId, extra: prevExtra} = payload;
console.log(prevExtra);
const newFavoriteItems = prevExtra.favoriteItems? prevExtra.favoriteItems.concat([itemId]) : [itemId];
console.log(newFavoriteItems);
return Api.editMember({id: memberId, extra: {...prevExtra, favoriteItems: newFavoriteItems}}, queryConfig).then((member) => Map(member));
},
onMutate: async (payload) => {
Expand All @@ -131,10 +129,9 @@ export default (queryClient: QueryClient, queryConfig: QueryClientConfig) => {

// Optimistically update to the new value
const { itemId, extra } = payload;
extra.favoriteItems = extra.favoriteItems
? extra.favoriteItems.concat([itemId])
: [itemId];
const member = { extra };
const newFavoriteItems = extra.favoriteItems ? extra.favoriteItems.concat([itemId]) : [itemId];

const member = {...extra, favoriteItems: newFavoriteItems};

queryClient.setQueryData(
CURRENT_MEMBER_KEY,
Expand Down

0 comments on commit 849e442

Please sign in to comment.