data-driven-forms / react-forms

React library for rendering forms.
https://data-driven-forms.org/
Apache License 2.0
302 stars 87 forks source link

Actions not re-evaluating on field re-render #1467

Closed jspannu919 closed 4 months ago

jspannu919 commented 4 months ago

Unlike resolveProps, actions are not getting re-evaluated when only the field is re-rendered as we don't re-evaluate action mapping in useFieldApi. Also, we remove the actions while preparing props in renderForm. Reproducer: https://codesandbox.io/p/sandbox/data-driven-forms-example-forked-zp5yjt?file=%2Fsrc%2FApp.js%3A44%2C35

Hyperkid123 commented 4 months ago

@jspannu919 Seems like the sandbox link does work. Cna you please it so we can check :slightly_smiling_face: ?

jspannu919 commented 4 months ago

Sorry, my bad. https://codesandbox.io/p/sandbox/data-driven-forms-example-forked-zp5yjt

Hyperkid123 commented 4 months ago

You are using a react hook within the action. This will never work. Hooks can't be conditional and can be called only within functions.

If you wish to conditionally mutate props based on the form state, you need a custom component. Action are here to map strings to JS functions, not to handle some extra internal component logic.

I've created a very basic sample here: https://codesandbox.io/p/sandbox/data-driven-forms-example-forked-zp5yjt

jspannu919 commented 4 months ago

We wrote a wrapper to re-evaluate action mapping on field re-render, at our end bcz we had use case where we send expressions from backend and use that to do things like disabling fields. Closing the issue. Thanks team!