Files
cunningham/packages/react/src/components/Forms/Select/stories-utils.tsx
Romain Le Cellier 3a6028f0ba 🐛(rect) fix rhf select example
clearing the select trigger a infinit loop
2023-09-27 15:38:48 +02:00

27 lines
791 B
TypeScript

import { Controller, useFormContext } from "react-hook-form";
import React from "react";
import { Select } from ":/components/Forms/Select/index";
import { SelectProps } from ":/components/Forms/Select/mono";
export const RhfSelect = (props: SelectProps & { name: string }) => {
const { control, setValue } = useFormContext();
return (
<Controller
control={control}
name={props.name}
render={({ field, fieldState }) => {
return (
<Select
{...props}
state={fieldState.error ? "error" : "default"}
text={fieldState.error?.message}
onBlur={field.onBlur}
onChange={(e) => setValue(field.name, e.target.value)}
value={field.value}
/>
);
}}
/>
);
};