🐛(rect) fix rhf select example

clearing the select trigger a infinit loop
This commit is contained in:
Romain Le Cellier
2023-09-21 17:28:03 +02:00
parent 034e299407
commit 3a6028f0ba
2 changed files with 7 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@openfun/cunningham-react": patch
---
Fix Select usage with react hook form

View File

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