InitialValues not available until Field is rendered
See original GitHub issueIn the example below I am creating a Form
object with an initialValue for one of its fields. However since the Field hasn’t been rendered yet the initialValue will not appear in formState.values
.
Is this expected behavior? My issue with this is that I have some scoped Forms that will render a different number of scope objects depending on the user that is viewing it.
const SomeComponent = props => {
return (
<div>
<h5>Component with formState:</h5>
<pre>
<code>{JSON.stringify(props.formState, null, 2)}</code>
</pre>
</div>
);
}
const ComponentWithFormState = withFormState(SomeComponent);
export default () => (
<Form initialValues={{name: 'abc'}}>
<ComponentWithFormState />
<button type="submit">Submit</button>
</Form>
);
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Form values not initialized from initialValues until 2nd render ...
To summarize, we are finding that values are not being initialized until the second render cycle for our reduxForm-ed components. Example being ...
Read more >Formik is Not Rendering Initial Values - Stack Overflow
On the first render Formik takes the initialValues as they are, so if the values didn't get updated yet you will not see...
Read more >FAQs | React Hook Form - Simple React forms validation
Why is the first keystroke not working? ... Double check if you are using value instead of defaultValue . React Hook Form is...
Read more >react-final-form - npm
There are 554 other projects in the npm registry using ... a message next to each field that is not an error that...
Read more >Creating forms from models - Django documentation
The blank choice will not be included if the model field has blank=False and an ... your model with initial values for the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hmm if what your saying in 3 is true then thats a bug. 1 and 2 are in fact expected behavior. In terms of the keep state. That might also be an issue. Need to figure out how the lib can make the decision to use the kept state or initial one 🤔
The keep state issue is now fixed in V2.1.9 https://codesandbox.io/s/q8v4k66zzw here is sandbox example use case