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, in that case the UI will
// be in an incorrect state
mutate('/api/data', [...data, text], false)
// send text to the API
await fetch('/api/data', {
method: 'POST',
body: JSON.stringify({ text })
})
// to revalidate the data and ensure is not incorrect
// we trigger a revalidation of the data
trigger('/api/data')
setText('')
}
destroy: attributes => {
client.namespace(namespace).resource(resource);
mutate(key, client.delete(id, attributes));
}
};
onClick={() => {
mutate("globalState", { ...data, name: value }, false)
}}
>
update: async attributes => {
client.namespace(namespace).resource(resource);
await mutate(key, requestToResponse({ ...data, ...attributes }), false);
fetch();
}
};
const update = attributes => {
return mutate(
key,
client
.namespace(namespace)
.resource(resource)
.update(key, attributes)
);
};
update: attributes => {
client.namespace(namespace).resource(resource);
mutate(key, client.update(id, attributes));
},
destroy: attributes => {