Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function handleSubmit(event) {
event.preventDefault()
// mutate current data to optimistically update the UI
// the fetch below could fail, so we need to revalidate
// regardless
setQueryData('todos', [...data, text], {
shouldRefetch: false,
})
try {
// send text to the API
await mutatePostTodo(text)
setText('')
} catch (err) {
console.error(err)
}
}
const update = attributes => {
setQueryData(key, previous => ({ ...previous, ...attributes }), {
shouldRefetch: false
});
return mutate(attributes, { updateQuery: key });
};