@roqueform/react
Version:
Hooks and components to integrate Roqueform with React.
39 lines (38 loc) • 1.35 kB
TypeScript
import { ReactElement, ReactNode } from 'react';
import { Field, ValueOf } from 'roqueform';
/**
* Properties of the {@link FieldRenderer} component.
*
* @template Field The rendered field.
*/
export interface FieldRendererProps<F extends Field> {
/**
* The field that triggers re-renders.
*/
field: F;
/**
* The render function that receive a rendered field as an argument.
*/
children: (field: F) => ReactNode;
/**
* If set to `true` then {@link FieldRenderer} is re-rendered whenever the {@link field} itself, its parent fields or
* descendant fields are updated. If set to `false` then {@link FieldRenderer} re-rendered only if the field was
* directly changed (updates from parent and descendants are ignored, even if they affect the value of the field).
*
* @default false
*/
eagerlyUpdated?: boolean;
/**
* Triggered when the field value received a non-transient update.
*
* @param value The new field value.
*/
onChange?: (value: ValueOf<F>) => void;
}
/**
* The component that subscribes to the field instance and re-renders its children when an event is dispatched onto the
* field.
*
* @template Field The rendered field.
*/
export declare function FieldRenderer<F extends Field>(props: FieldRendererProps<F>): ReactElement;