Next.js Discord

Discord Forum

show toast when formstate is not null

Unanswered
Banjara Hound posted this in #help-forum
Open in Discord
Banjara HoundOP
i have a form. that have something like this.
1. have handle Change for every input to set value and validate input on every change and show correct message.
2. then submit form and return response using server action and useFormState hook.
3. if form formState is not null. then show a toast with message that why that happen.
4. since formstate is not null here. i get toast every time i change input since cause re-render of component.
5. i tried to set formstate to null but not work since it's const.

so what should i do? i don't want remove handle change since i want to show correct error when user changing input values.

1 Reply

Banjara HoundOP
i found it.
put toast inside useEffect and add formSate as dependencies.