ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
14 lines (11 loc) • 438 B
text/typescript
import { FieldValues, useFormContext, useWatch } from 'react-hook-form';
// hook taken from https://react-hook-form.com/docs/usewatch/#rules
export const useFormValues = <
TFieldValues extends FieldValues = FieldValues,
>() => {
const { getValues } = useFormContext<TFieldValues>();
return {
...useWatch(), // subscribe to form value updates
...getValues(), // always merge with latest form values
};
};