'Calling a function after state is set
I have noticed that hooks set functions are asynchonous but I need to call a function once my new value has been set.
This is how my state looks:
const[agenda, setAgenda] = useState([{ id: "0", date:new Date(2022,0,21,13,25,0), titulo: "Test 1", obs:'Lorem ipsum dolor sit amet', prioridade:1,local:'-',lugar:'', diatodo:false },
{ id: "1", date:new Date(2022,0,21,13,25,0), titulo: "Test 2", obs:'Lorem ipsum dolor sit amet', prioridade:1,local:'-',lugar:'', diatodo:false }])
It's an array so I don't know how to do it, I have tried doing this:
setAgenda({[...agenda,obj]},testFunction);
Visual Studio Code gives me the following error though: Error
How should I do it? Thanks in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
