wsmd / react-use-form-state

📄 React hook for managing forms and inputs state

Home Page:http://react-use-form-state.now.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[bug] useFormState callback cache causes stale closures

derrickbeining opened this issue · comments

The implementation of useFormState is problematic because it caches callback functions passed to inputs.text et. al. This causes functions like onChange, validate, and onBlur to run with stale closures, namely, the closure with which they are initialised. This can be fixed simply by removing const callbacks = useCache(); from the implementation.

See PR at #76

Can you re-open this? That PR was reverted and this stale closure issue is making react-use-form-state unusable for me. We really need to be able to pass in an array of dependencies ala native hooks.

Any news on this?

Fix is on the way!

We really need to be able to pass in an array of dependencies ala native hooks.

and that shouldn't be needed! 😄

The latest release 0.13.1 addresses the stale closures problem. This is no longer be an issue!

Callbacks were originally cached for performance reasons (we don't want to re-render the entire form inputs any time the form state changes). This remains true with the latest release.

Demo (0.13.0): https://xii57.csb.app/
Demo (0.13.1): https://6evzz.csb.app/