Skip to content

Subscribe to state changes outside of React #12

@dan-lee

Description

@dan-lee

Hey @RichardLindhout! I am still very happy with this tiny but powerful library :)

I'd like to listen for state changes to trigger side effects (e.g. logging, tracking). For now I need to this in store.set itself, but I'd like to have this side effect free.

Maybe something along those lines:

const unsubscribe = myRidgeStore.subscribe((prevState, newState) => {
  // side effects here
})

Unfortunately onSet doesn't suffice as it happens after the state already has changed, I would also be fine with another option at store creation.
But in my opinion the approach I suggested is a little bit more approachable.

Thanks :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions