I just finished learning about redux middleware, and it seems really useful. However, I have a question regarding the return values of middleware.
I understand that some middleware return values (such as redux-promise
), while others like logging
do not - they simply return the result of next(action)
.
My concern is what happens if I want to use two middleware that both return values - won't they interfere with each other and only provide the output of the outermost middleware?
express/connect
middleware deals with this by allowing middleware to write their "results" to the req
and res
objects, but what is the solution in the context of redux?
EDIT
Let me give you a specific example of my dilemma:
I am using two pieces of middleware:
- A middleware that delays all dispatched actions by 3 seconds. This middleware returns a function that can be used to cancel the dispatch.
- Another middleware that simply returns the number 5 for a specific purpose.
Depending on how I chain these two middleware components, the output of my dispatch(action)
will either be the cancellation function or the number 5. But is there a way to obtain both of these results simultaneously?