optimistic insert item at index
This commit is contained in:
cv
2021-04-13 11:20:31 +02:00
parent 319cb3ab02
commit 2e50e488a3
@@ -30,10 +30,13 @@ export default function EventListWrapper() {
const previousEvents = queryClient.getQueryData(eventsNamespace); const previousEvents = queryClient.getQueryData(eventsNamespace);
// optimistically update object, temp ID until refetch // optimistically update object, temp ID until refetch
queryClient.setQueryData(eventsNamespace, (old) => [
...old, queryClient.setQueryData(eventsNamespace, (old) =>
{ ...newEvent, id: new Date().toISOString() }, old.splice(newEvent.order, 0, {
]); ...newEvent,
id: new Date().toISOString(),
})
);
// Return a context with the previous and new todo // Return a context with the previous and new todo
return { previousEvents }; return { previousEvents };