You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the TagInput component requires external state management to track tags via tags and setTags props. This approach, while functional, adds boilerplate code and makes the component less flexible for users who might not need to manage state externally.
To simplify state management and make the component more user-friendly, I suggest introducing useControllableState, a hook that checks whether the component is controlled or uncontrolled and allows it to handle state internally when necessary.
Current Behavior:
In the current version, users need to declare a state outside the TagInput component, like so:
const [tags, setTags] = React.useState<Tag[]>((form?.getValues?.('skills') as Tag[]) || []);
The TagInput then accepts tags and setTags as props:
<TagInput
{...field}
enableAutocomplete
autocompleteOptions={Skills}
limitToAutoComplete
placeholder="Enter skills"
tags={tags}
setTags={setTags}
/>
This approach works, but it requires the user to manage the state externally, even in scenarios where the state could be handled internally by the component itself.
Additional Context
Proposed Solution:
By introducing the useControllableState hook, we can make the TagInput component capable of handling its internal state without requiring external state management. This will reduce the need to declare external states and simplify the component's usage.
Tags and SetTags are still passed, but they are manually mutated in the tag form field directly by RHF (React Hook Form).
Feature description
Currently, the TagInput component requires external state management to track tags via tags and setTags props. This approach, while functional, adds boilerplate code and makes the component less flexible for users who might not need to manage state externally.
To simplify state management and make the component more user-friendly, I suggest introducing useControllableState, a hook that checks whether the component is controlled or uncontrolled and allows it to handle state internally when necessary.
Current Behavior:
In the current version, users need to declare a state outside the TagInput component, like so:
This approach works, but it requires the user to manage the state externally, even in scenarios where the state could be handled internally by the component itself.
Additional Context
Proposed Solution:
By introducing the useControllableState hook, we can make the TagInput component capable of handling its internal state without requiring external state management. This will reduce the need to declare external states and simplify the component's usage.
Tags and SetTags are still passed, but they are manually mutated in the tag form field directly by RHF (React Hook Form).
This hooks are used in most component library
Before submitting
The text was updated successfully, but these errors were encountered: