useState doesn't update as intended
Answered
Standard Chinchilla posted this in #help-forum
Standard ChinchillaOP
I'm trying to make a form that goes over different pages, so I have made a global state for just the form, but even tho my test form are the same I get different results, first page doesn't update second one is just wierd
all the code is here in github https://github.com/TOcvfan/formtest/
if I console.log e I get { fornavn: "whatever I typed" } on the first page and { fisse: "whatever I typed" } on the second page
all the code is here in github https://github.com/TOcvfan/formtest/
if I console.log e I get { fornavn: "whatever I typed" } on the first page and { fisse: "whatever I typed" } on the second page
Answered by Standard Chinchilla
instead of this
I used this
const onSubmitSignIn = async (e) => {
console.log(e)
setData({
...data,
e
})
router.push("/opret/bruger/info2");
}I used this
const onSubmitSignIn = async (e) => {
console.log(e)
setData(data => ({
...data,
...e
}))
router.push("/opret/bruger/info2");
}3 Replies
Standard ChinchillaOP
Okay apparently nobody knows the solution to my problem or don't want to tell me..
luckily I found out myself
luckily I found out myself
@Standard Chinchilla Okay apparently nobody knows the solution to my problem or don't want to tell me..
luckily I found out myself
Spotted Towhee
Perhaps you could share your solution then, so others learn from it?
Standard ChinchillaOP
instead of this
I used this
const onSubmitSignIn = async (e) => {
console.log(e)
setData({
...data,
e
})
router.push("/opret/bruger/info2");
}I used this
const onSubmitSignIn = async (e) => {
console.log(e)
setData(data => ({
...data,
...e
}))
router.push("/opret/bruger/info2");
}Answer