redux-watch | Watch/observe/monitor Redux store state changes | State Container library
kandi X-RAY | redux-watch Summary
kandi X-RAY | redux-watch Summary
Watch/observe/monitor Redux store state changes
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Watcher with a path
redux-watch Key Features
redux-watch Examples and Code Snippets
Community Discussions
Trending Discussions on redux-watch
QUESTION
I am trying to access the state.X of my store when Redux-watch store.subscribe() is triggered (by updating state.Y), but I can access just initial state values. I am using Redux-toolkit, React-redux, React-watch
When I call the "print" function after I press the UI button, my state is displayed with desired values, but when I call the "print" function in Redux-watch subscribe() function, the state.X has its initial values. Any idea what can be wrong?
Getting state from the store.
const date = useSelector((state) => state.calendar);
Print function: const print = () =>{console.log(date);}
Redux-watch subscribe function:
...ANSWER
Answered 2021-Mar-18 at 09:46In the end, I managed to get the state of the store in the subscribe() function by calling directly store.getState().
Though I did not find out why the variable "date" is in the time of the subscribe() method execution set to initial state value, I guess it's something with updating state in the time when the subscribe() function is called. So to get state in the subscribe() method:
QUESTION
Several of my components should be rendered only once, since then I just want them to listen to the changes in a global store and act correspondingly. But I can't make it: store.subscribe, and redux-watch I tried fired only when data has been dispatched but not when the store actually changed what means the corresponding function can't use this.props.bla because it's not updated yet. Is there some solution allowing to know when this.props.bla actually changed without using bla in the render function?
The example of a component:
...ANSWER
Answered 2020-Dec-27 at 23:53When you want to "respond" to a specific prop value updating then you should implement the componentDidUpdate
lifecycle method. In your case if you need to know when the injected position
prop value has updated, add a condition to compare the previous position
prop value against the current position
prop value.
QUESTION
Let's say i have a property in the store called state.items.byId
each time this is updated (various parts of the application) i want to intercept the value before i'ts updated and run a function to update some properties on it before it's updated.
I don't know the terminology and i'm quite new to redux, but if someone could point me in the right direction that would be great!
I have searched and found redux-watch
but i'm not 100% sure if this is the right approach
ANSWER
Answered 2020-May-28 at 04:39below shows the data flow in a redux application. View dispatches an action, the action object is a blue-print telling the reducer what changes it needs to make to the store state. Any change in the redux store state needs to pass through this cycle.
redux-watch provides you a subscription based mechanism notifying you after a property is changed. If you want to intercept a property before its changed you can write a custom middleware and handle any side-effects inside it.
QUESTION
I'm trying to differentiate different redux state changes and saw this github solution: Redux-watch In order to the watch function you're supposed to provide the redux store which can't figure out how to do. I'm passing the store down to this component through a provider for reference.
...ANSWER
Answered 2020-Feb-29 at 22:08If you need access to the store state in a component, you should be using the useSelector
hook or the connect
higher-order component. Don't try to set up store subscriptions yourself in components - React-Redux does that for you already.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install redux-watch
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page