-
Notifications
You must be signed in to change notification settings - Fork 145
Open
Description
Problem
Many input fields across our UI packages are facing issues such as:
- Default values not showing
Selectcomponents not registering values properlyundefinedvalues being returned
These issues are consistently resolved when using useController from React Hook Form (RHF) instead of the register method.
While trying to resolve these issues, I ended up using useController in many fields.
https://github.com/adityacodepublic/autoform/tree/fix-bugs
Improvement Suggestion
Move to using Controller in the react package, in the AutoFormField component, instead of relying on register. This change would:
- Fix form behavior issues: Components behave as expected without bugs.
- Decouple UI lib. from RHF: The UI package becomes form-library-agnostic, avoiding peer dependency on RHF.
- Simplify usage: Users don’t need to use
useControllermanually. - Extensible: Allows us to support other form libraries like TanStack Forms in the future with minimal changes.
Additional Context
- We are already using
useControllerinstead of register in many ui libs. - Since
Controllerwraps only theFieldComponentinsideAutoFormField, re-renders are scoped to just the FieldComponent. The outer AutoFormField or FieldWrapper does not re-render on controlled state changes.
return (
<FieldWrapper
label={getLabel(field)}
error={error}
id={fullPath}
field={field}
>
<Controller
name={fullPath}
disabled={field.fieldConfig?.inputProps?.disabled}
render={({ field: formField }) => (
<FieldComponent
label={getLabel(field)}
field={field}
value={value}
error={error}
id={fullPath}
key={fullPath}
path={path}
inputProps={{
error: error,
key: `${fullPath}-input`,
...field.fieldConfig?.inputProps,
...formField,
}}
/>
)}
/>
</FieldWrapper>
);
};@vantezzen Let me know your thoughts — happy to help implement this if it looks good to you.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels