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, or FormSpy. For Form, it will even infer the form values type if you provide initialValues.

    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\>
    

    v6.1.0...v6.2.0