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
Avatar
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>.
Image
Image
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

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