What is the proper type for this Form Submit event?
Answered
sh1ro posted this in #help-forum
sh1roOP
I get a TypeError on the
<Form> component. I don't know what should I use to define the handleSubmitfunction's e? Sorry, I'm new to NextJS's <Form>.Answered by Giant panda
Use a normal
form element then. The new next/form is only for very specific use-cases, not really one where you pass a client-side handler.14 Replies
Giant panda
Ctrl + Left Click on
action and your editor should bring you to the type definition of action.@Giant panda Ctrl + Left Click on `action` and your editor should bring you to the type definition of `action`.
sh1roOP
I did use that feature. But anything I changed to seem invalid to the attribute.
I have no idea about this actually.
Giant panda
Even hovering over it shows it clearly - you can see it's a function that takes
FormData.@Giant panda Even hovering over it shows it clearly - you can see it's a function that takes `FormData`.
sh1roOP
But if I changed it to
<FormData>, I can’t use e.target.value. Any suggestion?Giant panda
Use a normal
form element then. The new next/form is only for very specific use-cases, not really one where you pass a client-side handler.Answer
Giant panda
It is designed to be a lightweight form element or one that takes a server action and makes it progressively enhanced etc.
If you run client-side code, none of that matters.
sh1roOP
So my use case isn’t making any sense to the
<Form>’s rule and design?Giant panda
If you can't make use of progressive enhancement, prefetching etc. then no.
@Giant panda If you can't make use of progressive enhancement, prefetching etc. then no.
sh1roOP
Well then, thanks for helping me. I'm using the
form instead as you advise me to, and it just works fine as usual.