Releases: final-form/react-final-form
v6.0.1
v6.0.0
This release contains very minimal, edge-case, breaking changes.
Bug Fixes
- Fixed bug in form component rerendering not responding to changes in form state properly. #498 #487 #492
⚠️ Breaking Changes ⚠️
- Subscription changes will now be ignored. For some reason previous versions of React Final Form did extra work to allow you to change the
subscription
prop, causing the component to reregister with the Final Form instance. That is a very rare use case, and it was a lot of code to enable it. If you need to change your subscription prop, you should also change thekey
prop, which will force the component to be destroyed and remounted with the new subscription. parse={null}
andformat={null}
are no longer allowed. That was a bad choice of API design, which is probably why Flow doesn't allow theFunction | null
union type. #400 Passingnull
served the purpose of disabling the defaultparse
andformat
functionality. If you need to disable the existingparse
andformat
, you can pass an identity function,v => v
, toparse
andformat
.
< v6
<Field name="name" parse={null} format={null}/>
>= v6
const identity = v => v
...
<Field name="name" parse={identity} format={identity}/>
v5.1.2
v5.1.1
v5.1.0
New Features
- Used [email protected]'s new
beforeSubmit
callback to enableformatOnBlur
before submit #478 #470
v5.0.2
v5.0.1
v5.0.0
🎉 v5.0.0 – HOOKS!!! 🎉
First to explain why this change was made... To manage subscriptions to the internal 🏁 Final Form instance, 🏁 React Final Form has been using some legacy lifecycle methods that make the side effect of subscribing to an event emitter cumbersome. Such subscriptions are a perfect use case (no pun intended) for the new React.useEffect()
hook. In an effort to modernize and future proof the library, the entire thing has been rewritten to use hooks.
All the previous tests have been rewritten to use 🐐 React Testing Library, which is a superior way to test React components. None of the tests were removed, so all existing functionality from v4
should work in v5
, including some optimizations to minimize superfluous additional renders that were made possible by hooks.
⚠️ BREAKING CHANGES 😮
Don't worry...there really aren't that many.
- Requires
^[email protected]
. That's where the hooks are. 🙄 - All deprecated functions provided in
FormRenderProps
andFormSpyRenderProps
have been removed. They have been spitting warnings at you sincev3
, so you've probably already corrected for this. The following applies to:batch
blur
change
focus
initialize
mutators
reset
Rather than spreading the FormApi
into the render props, you are just given form
itself.
v4
<Form onSubmit={submit}>{({ reset }) => (
// fields here
<button type="button" onClick={reset}>Reset</button>
)}</Form>
v5
<Form onSubmit={submit}>{({ form }) => (
// fields here
<button type="button" onClick={form.reset}>Reset</button>
)}</Form>
Field
will no longer rerender when thevalidate
prop. Note: it will still always run the latest validation function you have given it, but it won't rerender when the prop is!==
. This is to allow the very common practice of providing an inline=>
function as a field-level validation function. This change will break the very rare edge case where if you are swapping field-level validation functions with different behaviors on subsequent renders, the field will no longer rerender with the new validation errors. The fix for this is to also change thekey
prop onField
any time you swap thevalidate
function. See this test for an example of what I mean. There's also a sandbox demonstrating the issue:
- The previously exported
withReactFinalForm
HOC has been removed. Now you should use theuseForm()
hook if you'd like to get the 🏁 Final Form instance out of the context. To ease your transition, you can make your own with a single line of code:
const withReactFinalForm = Component => props =>
<Component reactFinalForm={useForm()} {...props} />
😎 New Hook API 😎
Because it was so easy to do, 🏁 React Final Form now exports the useField
and useFormState
hooks that are used internally in Field
and FormSpy
respectively. Literally the only thing Field
and FormSpy
do now is call their hook and then figure out if you are trying to render with the component
, render
, or children
prop.
For example, before v5
, if you wanted to create a custom error component that only rerendered when touched
or error
changed for a field, you'd have to do this:
v4
const Error = ({ name }) => (
<Field name={name} subscription={{ touched: true, error: true }}>
{field =>
field.meta.touched && field.meta.error ? (
<span>{field.meta.error}</span>
) : null
}
</Field>
)
...but now you can do:
v5
const Error = ({ name }) => {
const field = useField(name, { subscription: { touched: true, error: true } })
return field.meta.touched && field.meta.error ? (
<span>{field.meta.error}</span>
) : null
}
Not too groundbreakingly different, but these hooks might allow for some composability that was previously harder to do, like this clever disgusting hack to listen to multiple fields at once.
Go forth and hook all the things! 🎣
Special thanks to @Andarist for giving me such an extensive code review on #467.
v4.1.0
🎉 New Features 🎉 (requires [email protected]
)
- Two new props to
Field
:defaultValue
andinitialValue
allow fine grain control over how your field values are initialized at the field level. #387 - Added
meta.modified
flag for all fields. A field becomes modified the first time its value changes. Previously, with dirty, if the user returned the value to the initial value, the form state had no evidence that the value had ever changed. This is what modified provides.
Bug Fixes
- Fixed
displayName
of context provider HOC #375
Type Fixes
- Updated
FieldProps.validate
type definition #413 - Add Typescript typings for third argument of
validate
function #429