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.

On initial value change, update props.value

See original GitHub issue

Bug, Feature, or Question?

Question

Current Behavior

How to update default values when the initial values change

export default withFormik({
    mapPropsToValues: (props: Props) => {
        return (
            {
                id: props.initialData.id,
                name: props.initialData.name
            }
        );
    },

Desired Behavior

Once the props value update re render the form Any support is helpful. Thank you

Additional Information

https://codesandbox.io/s/k5w5qn94z7


  • Formik Version:0.11.11

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
jaredpalmercommented, Mar 27, 2018

You can set enableReinitialize to true and then whenever you change props the form the form will reset

14reactions
vctormbcommented, May 6, 2018

@jaredpalmer is it possible to update the values without reseting the entire form? For example, imagine if I have a redux call and I want to wait to receive new props to populate some part of my form, but not reseting the another fields in the form.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React.useState does not reload state from props
useState() is only the initial value for that state. React isn't going to recognize that as changing the state, only setting its default ......
Read more >
How to update state from props in React - Robin Wieruch
In this brief walkthrough, I want to show you a use case where you would want to derive state from props and how...
Read more >
How to Fix the React useState Hook Not Setting Initial Value ...
We can make sure that a React component state updates when the prop value changes by watching the prop's value with the useEffect...
Read more >
Reacting to Prop Changes in a React Component | Pluralsight
The way to do this in the hooks API is by using the effect hook. The effect hook can either run after every...
Read more >
React Antipatterns: Props In Initial State
Summary · Keep the state in the parent component and make the child component fully controlled - pass the value and update function...
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