Next.js Discord

Discord Forum

What is the proper type for this Form Submit event?

Answered
sh1ro posted this in #help-forum
Open in Discord
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 Asian black bear
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.
View full answer

14 Replies

Asian black bear
Ctrl + Left Click on action and your editor should bring you to the type definition of action.
@Asian black bear Ctrl + Left Click on `action` and your editor should bring you to the type definition of `action`.
I did use that feature. But anything I changed to seem invalid to the attribute.
I have no idea about this actually.
Asian black bear
Even hovering over it shows it clearly - you can see it's a function that takes FormData.
@Asian black bear Even hovering over it shows it clearly - you can see it's a function that takes `FormData`.
But if I changed it to <FormData>, I can’t use e.target.value. Any suggestion?
Asian black bear
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
Asian black bear
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.
So my use case isn’t making any sense to the <Form>’s rule and design?
Asian black bear
If you can't make use of progressive enhancement, prefetching etc. then no.
@Asian black bear If you can't make use of progressive enhancement, prefetching etc. then no.
Well then, thanks for helping me. I'm using the form instead as you advise me to, and it just works fine as usual.