I have some crud in my application. In react as we can know, we can do live crud concurrently with posting data to API. Like this:
const handleSubmit = async (someData:string) => {
const result = await fetch('endpoint', {method:'POST', body:JSON.stringify(someData)})
const data = await result.json()
setDatas([...datas, data])
}
And when we wanna delete them we can do this:
const handleDelete = async (id:string) => {
const result = await fetch('endpoint', {method:'DELETE'})
const data = await result.json()
setDatas(datas.filter(data => data.id !== id))
}
But if we wanna add data and then delete it without refresh I can't delete the data, because I can't found id. How do I do it?