question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InitialValues not available until Field is rendered

See original GitHub issue

In 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
joepuzzocommented, Mar 8, 2019

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 🤔

1reaction
joepuzzocommented, Mar 8, 2019

The keep state issue is now fixed in V2.1.9 https://codesandbox.io/s/q8v4k66zzw here is sandbox example use case

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found