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
Had an issue using Register API of React Hook Form. Looking at the documentation found out that there's another way of handling components that don't return the original event object on the onChange function using the Controller API.
Example:
/** React Function Component Example* This works with either useForm & useFormContext hooks.*/import{FC}from'react'import{Controller,useFormContext}from'react-hook-form'importDatePicker,{DatePickerProps}from'react-date-picker/dist/entry.nostyle'constFormDateInput: FC<Omit<DatePickerProps,'onChange'>>=({
name,
...props})=>{constformMethods=useFormContext()const{ control }=formMethods??{}return(<Controllerrender={({ field })=><DatePicker{...props}{...field}/>}name={name??'date'}control={control}/>)}exportdefaultFormDateInput
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Had an issue using Register API of React Hook Form. Looking at the documentation found out that there's another way of handling components that don't return the original event object on the onChange function using the Controller API.
Example:
More details on Controller API Docs
Topic on StackOverflow:
https://stackoverflow.com/a/72749426/10369460
Beta Was this translation helpful? Give feedback.
All reactions