so I know that setState() is asonchrynus but I don't understand when It is. I always run into this problem when mapping lists in react. Specifically when I delete list element.
This function updates state instantly and rerenders array.map() function:
const handleHistoryDel = (index) => {
setHistory(history.filter((_, i) => i !== index));
};
And this one updates state but doesn't rerender:
const handleHistoryDel = (index) => {
let temp=history;
temp.splice(index,1)
setHistory(temp);
};
What is the difference? Should second function use some kind of callback? If so how would you implement one?