Skip to content

useStore hook #733

Open
Open
@billyrrr

Description

@billyrrr

Is your feature request related to a problem? Please describe.

  1. useFluxible hook is not as expressive as connectToStore.
  2. There is a lack of documentation and clear way to "subscribe" to values in store when using hooks.
  3. The hook can be optimized to rerender exactly when StoreA out of [StoreA, StoreB] changes

Describe the solution you'd like
const locationStore = useStore('UserGpsLocationStore')
which would trigger a rerender on user Gps location change. The Gps location value is used in multiple components (similar as context)

  1. MapWithTracking
  2. A "Complex-Event-Processing" module to determine if the user is currently at a designated location
  3. A view to indicate where the user is currently at
    Before, the user's GPS location can be read from the context, but current implementation of fluxible-addons-react no longer supports legacy react Context API. It seems that the better way is to implement a useStore hook with a more fine-grained control over the data.

Describe alternatives you've considered
1.
Using current connectToStore HOC solves the problem (but less elegantly).
A wrapper has to be implemented on top of a hook component connectToStore(<HookBasedComponent />, [StoreA, StoreB])
Downside:

  • Does not take advantage of React hook's optimization. Component may be frequently updated on props change.
  • Looks more complicated than a hook-based component and more difficult for IDE to refactor and track type hints

Using current useFluxible hook
I am not very clear on the behaviour of this hook (whether it would trigger a rerender on Store change). Either way, it seems that a more fine-grained hook would be better.

I am considering implementing this hook, but hope to get some advice and feedback from the community first.

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