how I can send the updated state and not just only rendering Hi guys , I am trying to send the updated state but it's always send the original one , count should be 1 not 0.
const [interest, setInterest] = useState({
course_id: 1,
count: 0,
});
const submitInterest = (e) => {
setInterest({
...interest,
count: interest.count+1,
});
e.preventDefault()
Inertia.put('learnerinterest', interest)
}
The count will be sent as 0 to the the put endpoint, as the setState has not been run yet. So interest isnt actually updated until the next render cycle
const data = {
...interest,
count: interest.count+1,
}
setInterest(data);
e.preventDefault()
Inertia.put('learnerinterest', {interest: data})
@demonz I just gave you an example of a fix? We send the changed data to inertia
Please sign in or create an account to participate in this conversation.