react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

[BUG] Form decorators should not change from one render to the next as new values will be ignored

Open adamklepacz opened this issue 5 years ago • 3 comments
trafficstars

Are you submitting a bug report or a feature request?

Please guys check the code down below in the sandbox. The same decorators but getting an error about decorators change. It is probably a bug. Cause when I console.log decorators they're always the same but I'm getting an error: Form decorators should not change from one render to the next as new values will be ignored

What is the current behavior?

Getting an error about decorators change. but they're the same. Check screenshot: Zrzut ekranu 2020-04-28 o 12 22 45

What is the expected behavior?

Should not throw an error if the decorators are the same.

Sandbox Link

https://codesandbox.io/s/naughty-panini-ycjd9?file=/src/App.js

What's your environment?

"react-final-form": "^3.6.3", "final-form": "^4.8.1", "final-form-arrays": "^1.0.4", "final-form-calculate": "^1.2.1",

Other information

adamklepacz avatar Apr 28 '20 10:04 adamklepacz

You ever make any progress on this @adamklepacz ? Having same issue.

BMCwebdev avatar May 14 '20 16:05 BMCwebdev

You can either wrap createDecorator with useEffect or move it outside of the render.

const rentTypeDecorator = useMemo(() => createDecorator(
    {
      field: 'details.base_rent_and_operation',
      updates: {
        'details.fixed_rent': (baseRentAndOperationValue) => !baseRentAndOperationValue,
      },
    },
    {
      field: 'details.fixed_rent',
      updates: {
        'details.base_rent_and_operation': (fixedRentValue) => !fixedRentValue,
      },
    },
  ), [])

evgeny-t avatar May 15 '20 09:05 evgeny-t

Move the createDecorator function outside of the function component

` import this from this import that from that

const focusOnError = createDecorator()

export const App = () => { all my App code } `

justinsgithub avatar Feb 04 '22 11:02 justinsgithub