Future Export: the useControl
hook
#962
Replies: 2 comments 8 replies
-
Hi, thank you or the amazing library and all the work you do! In our project we were already using I know I probably shouldn't have relied on the unstable API 😅 in the first place but I liked this API a lot. What is the plan for |
Beta Was this translation helpful? Give feedback.
-
Is |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The
useControl
hook is an experimental API released under thefuture
export. It's designed to address the limitations ofuseInputControl
, which works well for simple cases — but gets in the way for dynamic or custom UI components.useInputControl
automatically renders a hidden input for you, which makes it feel familiar to developers coming from traditional form libraries. But this abstraction has trade-offs:useControl
is a successor to the previously undocumentedunstable_useControl
hook. It gives you full control over how the base input is rendered and connected to Conform. You render the input, register it manually, and decide how and when to sync its state — while still benefiting from validation, metadata, and native event handling.The UI Libraries Integration Guide has also been updated with practical tips and examples for working with
useControl
. For more details on the API itself, see theuseControl
API reference.What's changed
Manual input registration with full control
Unlike
useInputControl
,useControl
doesn't render an input for you — you render and register the input manually. This gives you full control and avoids the limitations of automatic rendering.You are required to manage the base input, but the
useControl
hook helps simplify the setup — more so thanunstable_useControl
did:defaultValue
(ordefaultChecked
) touseControl
, and it will apply it when the input is first registered. If you're rendering your form server-side, you should still set the default value directly on the input if you care about the initial value before JavaScript loads.hidden
. If you want to delegate focus to a custom input component, set anonFocus
handler in the options. Conform will automatically apply the necessary accessibility attributes, includingaria-hidden
,tabIndex={-1}
, andstyle
rules to make the hidden input focusable but invisible to screen readers.New field metadata for default values
To simplify integration, each field now includes default-related metadata:
defaultValue
for text input, single radio button or single selectdefaultOptions
for multi-select or checkbox groupsdefaultChecked
for single checkboxThese values are computed automatically from your form's
defaultValue
:They make it easier to pass the correct values when initializing
useControl
.Refined control value
useControl
exposes a set of properties for working with various input types:control.value
Current value of the base input. Undefined if the registered input is a multi-select, file input, or checkbox group.
control.options
Selected options of the base input. Defined only when the registered input is a multi-select or checkbox group.
control.checked
Checked state of the base input. Defined only when the registered input is a single checkbox or radio input.
control.files
Selected files of the base input. Defined only when the registered input is a file input.
Group registration for checkbox or radio
You can register multiple checkbox or radio inputs as a group by passing an array of elements to
register()
. This is useful when the setup renders a set of native inputs that you want to re-use without re-implementing the group logic:If you don't need to re-use the existing native inputs, you can always represent the group with a single hidden multi-select or text input.
For complete examples, see the checkbox and radio group implementations in the React Aria example.
Examples
We've prepared examples for integrating with popular UI libraries, including a new example with React Aria components:
If the library you're using isn't listed or you run into issues, open a discussion — we're happy to help. Contributions are also welcome if you'd like to share an example.
Beta Was this translation helpful? Give feedback.
All reactions