final-form-calculate
Version:
Decorator for calculating field values based on other field values in 🏁 Final Form
29 lines (21 loc) • 646 B
TypeScript
import { Decorator } from 'final-form'
export type FieldName = string
export type FieldPattern = FieldName | RegExp | FieldName[]
export type UpdatesByName = {
[FieldName: string]: (value: any, allValues?: Object, prevValues?: Object) => any
}
export type UpdatesForAll = (
value: any,
field: string,
allValues?: Object,
prevValues?: Object,
) => { [FieldName: string]: any }
export type Updates = UpdatesByName | UpdatesForAll
export type Calculation = {
field: FieldPattern,
updates: Updates,
isEqual?: (a: any, b: any) => boolean,
}
export default function createDecorator(
...calculations: Calculation[]
): Decorator