Open tiagobnobrega opened 5 years ago
Hi, feel free to create pull-request.
Hi @lukashala Could you give an example how implement a Middleware? It could be possible apply a dispatcher in such Middleware?
By the way. Your solution it's great one!
Hi @ehhMoises, see my article here, I mention it at bottom part https://medium.com/simply/state-management-with-react-hooks-and-context-api-at-10-lines-of-code-baf6be8302c
Hi Again @lukashala
I would like to know, how do i send the dispatch's context to middleware? It is possible in such context?
Hi @ehhMoises, everything is possible :) One way could be to create some higher order function and wrap reducer with it.
Something like this:
const reducer = (state, action) => {...}
const withMiddleware = (reducer) => (state, action) => {
doAnythingYouWantHere();
return reducer(state, action);
}
const reducerWithMiddleware = withMiddleware(reducer);
Hi... First of all, thx for sharing this solution. I've found a way to support middleware/enhancers for This solution, there's still some testing and validation. Do You think It could be a nice addition?