const [interest, setInterest] = useState({
course_id: 1,
count: 0,
});
const submitInterest = (e) => {
setInterest({
...interest,
count: interest.count+1,
});
e.preventDefault()
Inertia.put('learnerinterest', interest)
}
Dec 8, 2022
6
Level 2
useState doesn't update on submission
Hi guys, I am tired , I am trying to send the data using Inertia.put but it is updated on the UI but it doesn't update when sending it via Inertia.put . help please , any suggestion
Level 102
@demonz Yeah I explained why in the other post. Shart version here. They interest variable isnt updated until the next render, so it is still 0.
An example of a fix
const data = {
...interest,
count: interest.count+1,
}
setInterest(data);
e.preventDefault()
Inertia.put('learnerinterest', {interest: data})
1 like
Please or to participate in this conversation.