Skip to content

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

Open
@jdeniau

Description

@jdeniau

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions