"use client"; import { useActionState, JSX } from "react"; import { addUserAction, FormState } from "../actions/UserActionsZod"; import SubmitButton from "./SubmitButton"; const initialState: FormState = { success: false, message: "", }; export default function AddUserForm(): JSX.Element { // useActionState receives (action, initialState) const [state, formAction] = useActionState(addUserAction, initialState); return (

Add New User using Zod Validation

{/* Global Success / Failure Alerts */} {state.message && (
{state.message}
)}
{/* Name Input */}
{state.errors?.name && ( {state.errors.name[0]} )}
{/* Email Input */}
{state.errors?.email && ( {state.errors.email[0]} )}
{/* Password Input */}
{state.errors?.pass && ( {state.errors.pass[0]} )}
{/* Submit Button with Loading Spinner */}
); }