reduce-reducers | Reduce multiple reducers into a single reducer | State Container library
kandi X-RAY | reduce-reducers Summary
kandi X-RAY | reduce-reducers Summary
Reduce multiple reducers into a single reducer from left to right
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of reduce-reducers
reduce-reducers Key Features
reduce-reducers Examples and Code Snippets
Community Discussions
Trending Discussions on reduce-reducers
QUESTION
I have a scenario where I have 2 reducers that are the result of a combineReducers
. I want to combine them together, but keep their keys at the same level on nesting.
For example, given the following reducers
...ANSWER
Answered 2019-Apr-28 at 22:56OK, although the problem was already solved in the meantime, I just wanted to share what solution I came up:
QUESTION
I am new to the react-redux application. My actions consist of a little hierarchy like this one:
...ANSWER
Answered 2019-Apr-30 at 17:22Nesting reducers is a bad practice. You will want to keep your reducers (and state slices) as flat as possible. Hence, splitting will yield a better developing experience in terms of updating slices of your state. Check combineReducers().
About the switch case:Consider refactoring your reducer's from switch formation
QUESTION
I have react 16.3.2, and today i attempted to upgrade it through yarn upgrade react@latest
it has upgraded the yarn.lock
's react@^16.8.2 but when I console.log
out the react version it still outputs 16.3.2
Did I miss something?
Here's my package.json
ANSWER
Answered 2019-Feb-14 at 22:18yarn upgrade
does not update package.json
, only the lock file. Actually, none of the yarn upgrade
flags do. There's a long discussion about this in here
You can do the following:
- Reinstall React with
yarn add react@latest
- Install a npm package to check updates, for example, npm-check-updates. Run it to update
package.json
and then tryyarn install
. - Or you can install that specific React version
yarn upgrade react@16.8.2
.
This is the intended behaviour, even though it is very confusing in the docs.
QUESTION
I have a store which is shaped like this:
...ANSWER
Answered 2018-Dec-05 at 13:39A reducer is simple a function that take state
and action
and returns a new state object, so I think this would do what you want..
QUESTION
I'm using Redux Offline in my Angular project, and now I want to enable cancelling an item in the outbox while in offline mode. Basically, I just want to filter on the outbox array to remove items I want to cancel/modify.
My problem is it is missing (undefined) from the state I receive in the top level reducer. I can see offline in the Redux Dev tool, and I can also get it via NgRedux.select() and NgRedux.getState().
Is there a reason why redux offline is not present in the state received in the reducers? Can I add it, and then change it via reducers? Or is there another to access and modify the outbox?
package.json:
...ANSWER
Answered 2018-Jun-25 at 09:09redux-offline
injects it's own reducer dynamically so you'll not be able to access it via your top level reducers. redux-offline
exposes it's queue via the config which will allow you to update the outbox to remove/add actions. If you want to remove an offline action whilst the user is offline I'd suggest making an offline action call with a specific action type (e.g. 'CANCEL_OFFLINE_ACTION'
) and handling it in queue.enqueue
to remove the action in the outbox that you don't want to propagate.
Here's a rough example:
QUESTION
Code comes from the reduce-reducer repo:
...ANSWER
Answered 2018-Jan-05 at 00:45reducers
is just a JavaScript array, and reducers.reduce
is therefore good ol' Array.reduce
. This takes a reducing function and an initial value to reduce. The reducing function can take four parameters but we only care about the first two here:
- accumulator: the object gradually being built, returned at the end of the reduce
- currentValue: the current array element
p
and r
are the accumulator
and currentValue
, above. p
starts out with the value of previous
. This is an array of functions (each reducer in turn is represented by r
) so calling:
QUESTION
I've 2 reducers A, B residing in packages A and B respectively. I've a store in package A which combines both reducers.
Package A consumes package B. However, package B has a form
which upon submission must update the components defined in package A. I've defined an action in package B and want reducer A to handle that action.
I am able to get to the case statement for the action but the state in the reducer A doesn't reflect the global state. I thought once the store's state was updated all the reducers states' which make up the store would be updated but that doesn't seem to be the case. Reducer A is maintaining its own state which is a subset of the global store state. How do I make reducer A access the state updates brought by reducer B?
One thought I had was to merge reducer B within A but that would make package B dependent on A. I haven't tried using redux-form
since we've our own internal components for form elements. Any other thoughts/suggestions?
Update : Adding some code, the action types are constants defined as strings. Upon submission of the form I want SUBMIT_COURSE_DATA
action to be dispatched and have the state updated in reducer A. Store is essentially using combineReducers
to combine the reducers A and B.
ANSWER
Answered 2017-Sep-19 at 22:36Per the Redux FAQ entry on sharing state between slice reducers:
Many users later want to try to share data between two reducers, but find that
combineReducers
does not allow them to do so. There are several approaches that can be used:
- If a reducer needs to know data from another slice of state, the state tree shape may need to be reorganized so that a single reducer is handling more of the data.
- You may need to write some custom functions for handling some of these actions. This may require replacing
combineReducers
with your own top-level reducer function. You can also use a utility such as reduce-reducers to runcombineReducers
to handle most actions, but also run a more specialized reducer for specific actions that cross state slices.- Async action creators such as redux-thunk have access to the entire state through
getState()
. An action creator can retrieve additional data from the state and put it in an action, so that each reducer has enough information to update its own state slice.
There's also many other third-party reducer utilities available, and some of those may be useful. In particular, you might want to look at ryo33/combine-section-reducers, convoyinc/combined-reduction, and KodersLab/topologically-combine-reducers.
update
Per your question about why "r
isn't a reducer", right now you have:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install reduce-reducers
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