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

Why not use useEffect and FormSpy?

Open nik-lampe opened this issue 5 years ago • 2 comments

Hello,

This is not a bug report, but more of a general question to this module.

I am currently rewriting my app to use React hooks and at this occasion I'm simplifying much of my code.

My calculate functions are very crowded because I keep them outside my component but they need data from my redux store. So i fetch this data inside my component and then pass it to the functions.

To prevent this I tried another approach: I created a FormSpy component which does nothing but retrieve the data from my store and my form state, then calculates what I need and then updates the form in a useEffect hook, when the calculated stuff changes.

When looking at this I realized, that I could rebuild all my calculate stuff with these "SubscriberComponents". This makes my code much cleaner.

My first thought was that these data fetching and calculating methods might occur unneccesary often, but I can wrap the calculation in useMemo with the used values from the form state in my dependency array.

Am I missing something else? Is there something I can do with this module that I can't do with my SubscriberComponents?

nik-lampe avatar Jul 31 '19 06:07 nik-lampe

Because this was around before hooks

wldcordeiro avatar Oct 04 '19 20:10 wldcordeiro

@nik-lampe I like that pattern, would you mind sharing your SubscriberComponents?

pgross41 avatar Mar 08 '22 20:03 pgross41