Use existing React Hook Form state
The optional adapter links field labels, errors, native refs and a working local submit handler.
Loads this example when you need it.
Keyboard
- Tab reaches the registered field.
- Invalid submit uses React Hook Form focus and error behaviour.
States covered
- Empty required input
- Validation error
- Submitted value
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-basic-react-hook-form.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import {useState} from 'react';
import {useForm} from 'react-hook-form';
import {Button,Input,OTPInput,Select,UIProvider} from '@bld8/ui';
import {RHFControl,RHFField} from '@bld8/ui/react-hook-form';
import '@bld8/ui/styles.css';
export default function HookFormExample(){
const form=useForm<{name:string;reviewer:string|null;code:string}>({defaultValues:{name:'',reviewer:null,code:''}}),[saved,setSaved]=useState('');
return <UIProvider><form onSubmit={form.handleSubmit(values=>setSaved(values.name+' / '+values.reviewer))}>
<RHFField control={form.control} name="name" label="Example workspace name" required rules={{required:'Enter an example name.'}}>{field=><Input {...field}/>}</RHFField>
<RHFControl control={form.control} name="reviewer" rules={{required:'Choose an example reviewer.'}}>{binding=><Select {...binding} label="Example form reviewer" required options={[{value:'maya',label:'Maya Chen',description:'Interface review'},{value:'sam',label:'Sam Rivera',description:'Keyboard review'}]}/>}</RHFControl>
<RHFControl control={form.control} name="code" rules={{validate:value=>value.length===6||'Enter six example digits.'}}>{binding=><OTPInput {...binding} label="Example form code" length={6} hint="Format validation only; no authentication service."/>}</RHFControl>
<Button type="submit">Submit hook form example</Button><p role="status">{saved?'Local result: '+saved:''}</p>
</form></UIProvider>;
}