Skip to content

Commit b6a7917

Browse files
committed
Added longwinded comment to explain the reasoning behind #465
1 parent a0f67cb commit b6a7917

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Field.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ describe('Field', () => {
290290
{...input}
291291
data-testid="name"
292292
onBlur={e => {
293-
input.onChange(e.target.value && e.target.value.toUpperCase())
293+
input.onChange(
294+
e.target.value && e.target.value.toUpperCase()
295+
)
294296
input.onBlur(e)
295297
}}
296298
/>

src/useField.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,16 @@ function useField<FormValues: FormValuesShape>(
119119
(event: ?SyntheticFocusEvent<*>) => {
120120
state.blur()
121121
if (formatOnBlur) {
122+
/**
123+
* Here we must fetch the value directly from Final Form because we cannot
124+
* trust that our `state` closure has the most recent value. This is a problem
125+
* if-and-only-if the library consumer has called `onChange()` immediately
126+
* before calling `onBlur()`, but before the field has had a chance to receive
127+
* the value update from Final Form.
128+
*/
122129
const fieldState = form.getFieldState(state.name)
130+
// this ternary is primarily to appease the Flow gods
131+
// istanbul ignore next
123132
state.change(
124133
format(fieldState ? fieldState.value : state.value, state.name)
125134
)

0 commit comments

Comments
 (0)