Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why not use useEffect and FormSpy? #31

Open
nik-lampe opened this issue Jul 31, 2019 · 2 comments
Open

Why not use useEffect and FormSpy? #31

nik-lampe opened this issue Jul 31, 2019 · 2 comments

Comments

@nik-lampe
Copy link

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?

@wldcordeiro
Copy link

Because this was around before hooks

@pgross41
Copy link

pgross41 commented Mar 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants