onSubmit: {(values, { setSubmitting }) => {
console.log(values) // Just to be sure you have them correct
// POST request
axios.post('http:localhost:portNUM', values) // Add headers if you have any.
.then(response => console.log(response))
.catch(error => console.log(error))
.finally(() => setSubmitting(false))
}
}
In your second picture, it might be easier to send the data in the onSubmit.
onSubmit: {(values, { setSubmitting }) => {
console.log(values) // Just to be sure you have them correct
// POST request
axios.post('http:localhost:portNUM', values) // Add headers if you have any.
.then(response => console.log(response))
.catch(error => console.log(error))
.finally(() => setSubmitting(false))
}
}
It might also be easier to use a useEffect within the onSubmit, just to make life a bit easier. If you know how to use react hooks and if not, I would recommend learning them.
发布评论
评论(1)
您是否尝试过以
axios.post
向后端发送formular
。 axios post requests 和连接在您的第二张图片中,在
onsubmit
中发送数据可能会更容易。在
onsubmit
中使用使用
也可能更容易,只是为了使生活变得更加轻松。如果您知道如何使用React Hooks,并且如果没有,我建议您学习它们。Have you tried sent
Formular
withaxios.post
to your backend. Some info on axios post requests and connecting frontend to backend.In your second picture, it might be easier to send the data in the
onSubmit
.It might also be easier to use a
useEffect
within theonSubmit
, just to make life a bit easier. If you know how to use react hooks and if not, I would recommend learning them.