📝(react) add RHF examples

Rework a bit the recent work made on RHF example to make some component
more generic, such as RhfSelect and RhfDatepicker, which is based on a
design using RHF context hooks to provide a seamless integration.

Fixes #144
This commit is contained in:
Nathan Vasse
2023-08-29 16:18:30 +02:00
committed by NathanVss
parent 90a8f559b4
commit 468c8161eb
14 changed files with 460 additions and 468 deletions

View File

@@ -0,0 +1,27 @@
import { Controller, useFormContext } from "react-hook-form";
import React from "react";
import {
DatePicker,
DatePickerProps,
} from ":/components/Forms/DatePicker/DatePicker";
export const RhfDatePicker = (props: DatePickerProps & { name: string }) => {
const { control } = useFormContext();
return (
<Controller
control={control}
name={props.name}
render={({ field, fieldState }) => {
return (
<DatePicker
{...props}
state={fieldState.error ? "error" : "default"}
text={fieldState.error?.message}
onChange={field.onChange}
value={field.value}
/>
);
}}
/>
);
};