final-form / final-form/react-final-form

Bug: Initial value does not match value on useFormState

Open
#887 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

### Are you submitting a **bug report** or a **feature request**?
Bug report

### What is the current behavior?
**If**

1. A `` is mounted after the parent `` has already been mounted in a separate child component
2. The `` is provided an `initialValue`
3. The form values are extracted via `useFormState` in the separate child component

**Then**

The form value of the `` is `undefined` rather than being the `initialValue` on the first mount. After the first mount, the correct value is shown.

### What is the expected behavior?

The form value of the `` should be the initial value and not `undefined`.

### Sandbox Link

https://codesandbox.io/s/stoic-mountain-cdjf9?file=/index.js

### What's your environment?

React Final Form version: 6.5.2
Final Form version: 4.20.1
OS: Ubuntu 20.04 LTS
Browser: Chrome 87.0.4280.141 (Official Build) (64-bit)
Node: v15.5.1

### Other information
To reproduce, simply click the show button in the sandbox. Once clicked, look at the console, and observe the `undefined` is printed rather than the `initialValue` (in my case the string "Sam").

My current workaround is to use the `changeValue` mutation to initialized the `` rather than `initialValue`, but this is not as clean.

Contributor guide

Open the contributing guide

Research direction

Start with the CodeSandbox reproduction and inspect how a separately mounted with initialValue is registered while the parent is already mounted. Trace the first useFormState value and compare it with the value after the first mount. Done means the first reported form value is the field's initialValue rather than undefined.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.