I would love a short code review of "my" implementation of optimistic ui patterns. I'm using SWR, immer and a custom fetch hook to do most of the heavy lifting. However, I'm not really sure if this is indeed the way to do it. Especially when it comes to asigning a temporary id to the optimistically generated item. Shouldn't I clear it somewhere? May it cause issues?
const spawn = async flavour => {
const payload = {
planId: flavour.id,
name: 'test',
description: '',
}
mutate(
'/account/instances',
produce(draft => {
draft.push({
...payload,
id: uuid(),
plan: {name: flavour.name},
state: {status: 'PENDING'},
image: {name: flavour.image.name},
})
}),
false
)
mutate(
'/account/instances',
await doFetch('/account/instances', 'post', payload)
)
}
Thanks!