useFormValues
useFormValues returns the current values of all form fields, reactively updated as the user types. Useful for implementing conditional field logic.
Import
import { useFormValues } from "@phpcreation/frontend-crud-react-nextjs-bundle/hooks/useFormValues";Usage
import { useFormValues } from "...";
import { useForm } from "react-hook-form";
function DynamicForm() {
const form = useForm();
const values = useFormValues(form);
return (
<form>
<input {...form.register("type")} />
{values.type === "business" && (
<input {...form.register("vatNumber")} />
)}
</form>
);
}Parameters
| Param | Type | Description |
|---|---|---|
form | UseFormReturn | React Hook Form instance |
fields | string[] | Optional — watch only specific fields |
Returns
An object with the current form field values, re-rendered on every change.
Related
Last updated on