react-simply icon indicating copy to clipboard operation
react-simply copied to clipboard

Middleware Support

Open tiagobnobrega opened this issue 6 years ago • 6 comments

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?

tiagobnobrega avatar Apr 19 '19 13:04 tiagobnobrega

Hi, feel free to create pull-request.

lukashala avatar May 15 '19 08:05 lukashala

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!

ehhMoises avatar Sep 21 '19 23:09 ehhMoises

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

lukashala avatar Sep 22 '19 09:09 lukashala

Hi Again @lukashala

I would like to know, how do i send the dispatch's context to middleware? It is possible in such context?

ehhMoises avatar Sep 23 '19 14:09 ehhMoises

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);

lukashala avatar Oct 01 '19 13:10 lukashala

https://transang.me/get-state-callback-with-usereducer/

chestermjr avatar Jun 29 '20 12:06 chestermjr