const mutation = useMutation({
mutationFn: (inventory: Inventory) => createInventory(org_slug, inventory),
onMutate: async (inventory: Inventory) => {
//optimistic insert with temp_id
const temp_id = await optimisticInsertList(queryClient, ['orgs', org_slug, 'inventories'], inventory)
return { temp_id };
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['orgs', org_slug, 'inventories'] });
},
onSuccess: async (data, variables, { temp_id }) => {
// update state with new id
await AsyncStorage.setItem(temp_id, data.id.toString());
console.log('temp_id was set to', temp_id, 'and the new id is', data.id);
optimisticUpdateList(queryClient, ['orgs', org_slug, 'inventories'], data, temp_id);
},
mutationKey: ['orgs', org_slug, 'inventories'],
})
const mutation = useMutation({
mutationFn: (inventory: Inventory) => createInventory(org_slug, inventory),
onMutate: async (inventory: Inventory) => {
//optimistic insert with temp_id
const temp_id = await optimisticInsertList(queryClient, ['orgs', org_slug, 'inventories'], inventory)
return { temp_id };
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['orgs', org_slug, 'inventories'] });
},
onSuccess: async (data, variables, { temp_id }) => {
// update state with new id
await AsyncStorage.setItem(temp_id, data.id.toString());
console.log('temp_id was set to', temp_id, 'and the new id is', data.id);
optimisticUpdateList(queryClient, ['orgs', org_slug, 'inventories'], data, temp_id);
},
mutationKey: ['orgs', org_slug, 'inventories'],
})