import { Controller } from "https://deno.land/x/netzo@0.5.63/deps/react-hook-form.ts";
Component based on useController
hook to work with controlled component.
Examples
Example 1
Example 1
function App() {
const { control } = useForm<FormValues>({
defaultValues: {
test: ""
}
});
return (
<form>
<Controller
control={control}
name="test"
render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
<>
<input
onChange={onChange} // send value to hook form
onBlur={onBlur} // notify when input is touched
value={value} // return updated value
ref={ref} // set ref for focus management
/>
<p>{formState.isSubmitted ? "submitted" : ""}</p>
<p>{fieldState.isTouched ? "touched" : ""}</p>
</>
)}
/>
</form>
);
}
type
<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: ControllerProps<TFieldValues, TName>) => import("https://esm.sh/v128/@types/react@18.2.38/X-ZS9yZWFjdCxyZWFjdC1kb20/index.d.ts").ReactElement<any, string | import("https://esm.sh/v128/@types/react@18.2.38/X-ZS9yZWFjdCxyZWFjdC1kb20/index.d.ts").JSXElementConstructor<any>>