Skip to content

Commit de0f627

Browse files
authored
Changed parse and format API to appease Flow gods (#496)
1 parent 604264c commit de0f627

15 files changed

+260
-269
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
✅ Opt-in subscriptions - only update on the state you need!
1717

18-
✅ 💥 [**2.8k gzipped**](https://bundlephobia.com/result?p=react-final-form) 💥
18+
✅ 💥 [**3.0k gzipped**](https://bundlephobia.com/result?p=react-final-form) 💥
1919

2020
---
2121

@@ -532,11 +532,11 @@ well as any non-API props passed into the `<Field/>` component.
532532

533533
_**Before using this prop, read and understand the 🏁 Final Form documentation on [`initialValue`](https://github.com/final-form/final-form#initialvalue-any) and [`defaultValue`](https://github.com/final-form/final-form#defaultvalue-any)!**_
534534

535-
#### `format?: ((value: any, name: string) => any) | null`
535+
#### `format?: ((value: any, name: string) => any)`
536536

537537
A function that takes the value from the form values and the name of the field and formats the value to give to the input. Common use cases include converting javascript `Date` values into a localized date string. Almost always used in conjunction with `parse`.
538538

539-
**Note: If you pass `null` to `format`, it will override the default behavior of converting `undefined` into `''`. If you do this, making sure your inputs are "controlled" is up to you.**
539+
**Note: If you would like to disable the default behavior of converting `undefined` to `''`, you can pass an [identity function](https://en.wikipedia.org/wiki/Identity_function), `v => v`, to `format`. If you do this, making sure your inputs are "controlled" is up to you.**
540540

541541
#### `formatOnBlur?: boolean`
542542

@@ -554,11 +554,11 @@ If `true`, the `format` function will only be called when the field is blurred.
554554

555555
The name of your field. Field values may be deeply nested using dot-and-bracket syntax. [Learn more about Field Names](https://github.com/final-form/final-form#field-names).
556556

557-
#### `parse?: ((value: any, name: string) => any) | null`
557+
#### `parse?: ((value: any, name: string) => any)`
558558

559559
A function that takes the value from the input and name of the field and converts the value into the value you want stored as this field's value in the form. Common usecases include converting strings into `Number`s or parsing localized dates into actual javascript `Date` objects. Almost always used in conjuction with `format`.
560560

561-
**Note: If you pass `null` to `parse`, it will override the default behavior of converting `''` into `undefined`, thus allowing you to have form values of `''`.**
561+
**Note: If would like to override the default behavior of converting `''` to `undefined`, you can pass an [identity function](https://en.wikipedia.org/wiki/Identity_function), `v => v`, to `parse`, thus allowing you to have form values of `''`.**
562562

563563
#### `render?: (props: FieldRenderProps) => React.Node`
564564

0 commit comments

Comments
 (0)