From e7f1fc8d04a01df61851a620d5a73cce23aefe6b Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Wed, 21 Apr 2021 23:17:23 +0200 Subject: [PATCH] bugfix on optimist updates --- .../src/features/editors/list/EventListWrapper.jsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/client/src/features/editors/list/EventListWrapper.jsx b/client/src/features/editors/list/EventListWrapper.jsx index 92de1508b..f4d41ed48 100644 --- a/client/src/features/editors/list/EventListWrapper.jsx +++ b/client/src/features/editors/list/EventListWrapper.jsx @@ -30,13 +30,12 @@ export default function EventListWrapper() { const previousEvents = queryClient.getQueryData(eventsNamespace); // optimistically update object, temp ID until refetch - - queryClient.setQueryData(eventsNamespace, (old) => - old.splice(newEvent.order, 0, { - ...newEvent, - id: new Date().toISOString(), - }) - ); + let optimistic = [...previousEvents]; + optimistic.splice(newEvent.order, 0, { + ...newEvent, + id: new Date().toISOString(), + }); + queryClient.setQueryData(eventsNamespace, optimistic); // Return a context with the previous and new todo return { previousEvents };