UNPKG

@baseplate-dev/ui-components

Version:

Shared UI component library

32 lines 1.01 kB
import { useController } from 'react-hook-form'; import { mergeRefs } from '../utils/refs.js'; /** * A hook to wrap useController from react-hook-form that allows * passing in properties and refs that will be merged with the * controller's properties and ref. */ export function useControllerMerged(props, options, ref) { const { onChange, onBlur, disabled } = options; const controllerReturnValue = useController({ ...props, disabled: props.disabled, }); const { field } = controllerReturnValue; return { ...controllerReturnValue, field: { ...field, ref: mergeRefs(field.ref, ref), onChange: (value) => { field.onChange(value); onChange?.(value); }, onBlur: (e) => { field.onBlur(); onBlur?.(e); }, disabled: disabled ?? field.disabled, }, }; } //# sourceMappingURL=use-controller-merged.js.map