Next.js Discord

Discord Forum

Does a form with validation notices require 'use client'?

Unanswered
Kerry Ann posted this in #help-forum
Open in Discord
Hello. Working on a form. It renders fine as a server side component using server-side actions. My question is; is there a way to have the client deliver validation errors to the user without adding state and requiring it to be a client-side component?

6 Replies

Rainbow trout
No
If your server action returns a response to the client, react has to update the DOM to show a validation error
also useFormState actualy works if user has no js!
well useFormState requires use client doesn't it
anything not doable with purely html/css and not covered by react must be in client components.

so <input type="number" required /> to enforce that the value must be a number and must not be empty – this doesn't require a client component.

but if you want to show a custom error message or perform custom validation criteria, you need a client component.

client components aren't bad. this is important so i will repeat it: client components aren't bad. use them where you need them.
@joulev well useFormState requires use client doesn't it
i meant it does, but nextjs is nice with pre rendering if it was server action run with no js