final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.38k stars 480 forks source link

FormSpy: provide `form` API to `onChange` callback #412

Open Sharakai opened 5 years ago

Sharakai commented 5 years ago

Happy to work on this and PR it up from my fork.

Are you submitting a bug report or a feature request?

Feature request

What is the current behavior?

The FormSpy#onChange callback is only called with the form state and not the form FormAPI, but the render child is.

What is the desired behavior?

For the form FormAPI to be available in the onChange callback, as it is with the render method.

I can't see anything that would block this, and the renderProps object creation logic could be put into a private function on the FormSpy to ensure render and onChange are kept in-sync.

What's your environment?

Final-Form v4.11.0 React-Final-Form v4.0.2

Other information

Loving the library and the idea of using the Observer pattern - Very clean and easy to follow :+1:

ricovitch commented 5 years ago

Would also love to get previous form values in the onChange callback.

That would allow to compare previous/new values and implement field dependencies logic in there, like i'm trying to solve here : https://stackoverflow.com/questions/56700655/simple-way-to-update-form-values-depending-on-changes-with-react-final-form

s97712 commented 3 years ago

any update?