Skip to content

Why not use useEffect and FormSpy? #31

@nik-lampe

Description

@nik-lampe

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions