Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the component re-render, prevValues will be an empty object and the calculated values will the be broken #52

Open
jdeniau opened this issue Jul 13, 2021 · 0 comments

Comments

@jdeniau
Copy link

jdeniau commented Jul 13, 2021

What is the current behavior?

If a hook make the component re-render, then the prevValues will be an empty object and the "updates" function are triggered even if the values did not change

What is the expected behavior?

The "update" function should probably not be triggered, but they are probably because the prevValues is an empty object, which should not happen either

Sandbox Link

My current fix

const decorator = createDecorator({
  field: 'foo',
  updates:  (fieldValue, fieldName, allValues, prevValues) => {
    if (typeof prevValues[fieldName] === 'undefined') {
      return {};
    }

    // do real stuff
  }
})

Extracted from the final-form-calculate example: https://codesandbox.io/s/react-final-form-calculated-fields-forked-wpm4f?file=/index.js

What's your environment?

  • final-form: 4.12.0
  • final-form-calculate: 1.3.2
  • react-final-form: 5.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant