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.

<Field> initialValue / defaultValue prop

See original GitHub issue

Are you submitting a bug report or a feature request?

feature request

What is the current behavior?

A <Form> is required to be provided initialValues to set default values for fields.

What is the expected behavior?

<Field> can accept a prop initialValue or defaultValue that is registered with the parent <Form>'s initial values.

This would be oober convenient in many cases where fields are dynamically generated or conditionally rendered in the <Form>.

I’m happy to work up a PR if you’re accept/review the effort @erikras

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:22
  • Comments:31 (9 by maintainers)

github_iconTop GitHub Comments

12reactions
valstucommented, Aug 13, 2019

I have to agree, I also expected the functionality to be exactly what @crobinson42 and @redbmk expected.

So logic would be something like this: Check if initialValue in <Field /> exists? yes ==> use that value no ==> check if initialValues exists in <Form /> yes ==> use that value no ==> use defaultValue in <Field />

Currently the defaultValue will override both initialValue and initialValues

https://codesandbox.io/s/react-final-form-simple-example-yx7bh

9reactions
erikrascommented, Mar 4, 2019

Published a solution in react-final-form@4.1.0 and final-form@4.12.0. Let me know what you guys think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting a default value for an Input element in React | bobbyhadz
Pass the default value as a parameter to the useState hook for controlled fields. Set the defaultValue prop on uncontrolled input fields. App.js....
Read more >
Final Form Docs – `FieldProps`
The initial value for the field. This value will be used to calculate dirty and pristine by comparing it to the current value...
Read more >
React/ReactJS: Difference between defaultValue and value
In React, defaultValue is used with uncontrolled form components whereas value is used with controlled form components. They should not be used together...
Read more >
React - change input defaultValue by passing props
You can get around this if you need to by passing a key to the wrapper component, like on your Field or App...
Read more >
Uncontrolled Components - React
Component { constructor(props) { super(props); this. ... you often want React to specify the initial value, but leave subsequent updates uncontrolled.
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