♻️(react) fix rhf reset with Input
when using reset(), Input field value wasn't updated
This commit is contained in:
26
packages/react/src/components/Forms/Input/stories-utils.tsx
Normal file
26
packages/react/src/components/Forms/Input/stories-utils.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Controller, useFormContext } from "react-hook-form";
|
||||
import React from "react";
|
||||
import { Input, InputProps } from ".";
|
||||
|
||||
export const RhfInput = (props: InputProps & { name: string }) => {
|
||||
const { control, setValue } = useFormContext();
|
||||
return (
|
||||
<Controller
|
||||
control={control}
|
||||
name={props.name}
|
||||
render={({ field, fieldState }) => {
|
||||
return (
|
||||
<Input
|
||||
{...props}
|
||||
aria-invalid={!!fieldState.error}
|
||||
state={fieldState.error ? "error" : "default"}
|
||||
text={fieldState.error?.message}
|
||||
onBlur={field.onBlur}
|
||||
onChange={(e) => setValue(field.name, e.target.value)}
|
||||
value={field.value}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user