react-final-form v6.2.0 Release Notes
Release Date: 2019-06-14 // almost 5 years ago-
π TypeScript fixes
- 0οΈβ£ Use the same default for FormValues type in all declared types (#525)
- 0οΈβ£ Replace empty object default type with any object (#526)
- π¨ Refactor getContext back to a simple context file (#524)
π New Features
- Strongly typed field values (#530)
- β Added tsx generic typings for Field, Form, and FormSpy components (#522)
For Typescript users, you can take advantage of JSX Generics, so you can specify the type of your form values or field value directly in the JSX call to
Form
,Field
, orFormSpy
. ForForm
, it will even infer the form values type if you provideinitialValues
.Behold this code:
interface MyValues { firstName: stringlastName: string}const initialValues: MyValues = { firstName: 'Erik', lastName: 'Rasmussen'}const onSubmit = (values: MyValues) =\> { ajax.send(values) } {/\* Typescript will complain if the type of initialValues is not the same as what is accepted by onSubmit\*/} \<Form onSubmit={onSubmit} initialValues={initialValues}\> {({ handleSubmit, values }) =\> { // π₯ Type of values is inferred from the type of initialValues π₯return ( \<form onSubmit={handleSubmit}\> {/\* π Field values are strongly typed using JSX generics π \*/} \<Field\<string\> name="firstName" component={TextInput} /\> \<Field\<string\> name="lastName" component={TextInput} /\> \<Field\<number\> name="age" component={NumberInput} /\> \<button type="submit"\>Submit\</button\> \</form\> ) }} \</Form\>