redux-batched-subscribe | store enhancer for https : | State Container library
kandi X-RAY | redux-batched-subscribe Summary
kandi X-RAY | redux-batched-subscribe Summary
store enhancer for https://github.com/reactjs/redux which allows batching subscribe notifications.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Creates a new batch of listeners .
- Subscribes to a given listener .
- Notifies all listeners of this array .
- Makes the current listeners .
- Dispatches an action .
- Notify listeners of a batch of listeners .
redux-batched-subscribe Key Features
redux-batched-subscribe Examples and Code Snippets
Community Discussions
Trending Discussions on redux-batched-subscribe
QUESTION
I have a component that needs to hide/show content based on whether the user is logged in or not. My Redux logger is showing the proper state change but the connected component is not re-rendering. At first I figured it was a mutation issue, however after attempting the same thing with immutable.js
and redux-starter-kit
's createReducer
with no success, I figured otherwise.
It's my understanding that when using mapStateToProps
the component should re-render the same as if it were local state.
Reducer:
...ANSWER
Answered 2019-Feb-10 at 23:16You have to wire up Redux in Combination with batchedSubscribe
correctly.
Here are the docs with a short guide: https://github.com/tappleby/redux-batched-subscribe
QUESTION
(sorry if similar question is asked, but I found ones on multiple action dispatches and re using the redux-batched-subscribe. That is not what I want)
I need to produce a dashboard similar to one shown below.
It uses three sources - DataSet1 (amounts added by users), DataSet2 and DataSet3.
DataSet2 and DataSet3 are derived from DataSet1 (i.e. certain calculations are done on DataSet1) using utils/function.
Any time DataSet1 changes (user adds a new amount, edit or deletes it) DataSet2 and DataSet3 should be recalculated and dashboard should instantly update entirely.
I am trying to design it to avoid repetitive recalculations and circular re-renderings.
I am thinking of doing it using Redux-Thunk.
What is the React way of doing similar tasks ?
Thank you !
EDIT: Removed unneeded detail, added Reselect to tags
...ANSWER
Answered 2018-Jul-27 at 20:01Welcome to React and Redux - it's awesome when you get the hang of it.
I presume you are using the react-redux
package to handle the binding between React and Redux. This package provides a class called Provider
which you wrap your application in. Provider does several things, but one of the big ones is that it subscribes to the store and triggers a re-render when the store changes.
As @zzzzBov mentioned, derived values should not be added to the store. For that we use selectors. In your case, that would mean DataSet1 lives in the store, and both DataSet2 and DataSet3 would be calculated by a selector. Just to make this clear, here is the flow of events when a user changes DataSet1:
- User changes DataSet1, a function you have defined in
mapDispatchToProps()
dispatches an action on the store. - The reducers run, generating a new state object.
- Any subscribers to the store are called and passed the new state object (in this case, Provider).
- Provider triggers an efficient re-render of the components (by efficient I mean it checks to see if the piece of state they select in
mapStateToProps()
has changed). - Your components responsible for rendering DataSet2 and DataSet3 select DataSet1 from the store, and derive DataSet2 and DataSet3 on the fly, then pass them on to their respective components.
If you don't want the DataSet2 and DataSet3 components to re-render on every change to the store, use the library reselect
. Reselect caches derived values, which in turn avoids spurious re-renders. When the state changes, Reselect checks to see if its input values have changed, if they have, it recomputes the output. Your components then select from Reselect instead of selecting directly from the state object.
Hopefully that helps. Good luck!
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install redux-batched-subscribe
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