Subscribe to state changes outside of React
See original GitHub issueHey @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 😃
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Update component state from outside React (on server ...
My main question is, is it possible to trigger a component state change from outside react (in this case on server response)?
Read more >How to subscribe to state outside React component in Redux ...
Coding example for the question How to subscribe to state outside React component in Redux Toolkit?-Reactjs.
Read more >Access the Redux Store Outside a React Component
Access the Redux Store Outside a React Component · Option 1: Export the Store · Option 2: Access Redux State from a Thunk...
Read more >Context - React
A React component that subscribes to context changes. ... inside the ThemeProvider // uses the theme from state while the one outside uses...
Read more >Redux Fundamentals, Part 5: UI and React
Those UI binding libraries handle the details of subscribing to the store and efficiently updating the UI as state changes, so that you ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Will try to add within two weeks
And possible unsubscribing?