use-reducer-with-side-effects icon indicating copy to clipboard operation
use-reducer-with-side-effects copied to clipboard

add support for middleware

Open conorhastings opened this issue 5 years ago • 4 comments

in a perfect world it could support redux middleware

conorhastings avatar Jan 06 '20 19:01 conorhastings

What do you envision the API looking like? fwiw I currently build a middleware system on top of the API that already exists

jamesplease avatar Jan 06 '20 23:01 jamesplease

3rd arg and or partial application

useReducer(middleware)(state, cb => {})

this breaks direct compat tho

or useReducer(state, cb, middleware) middleware being an array that gets run through dequentially being passed the subsequent state and returning either state or next(state)

since you have obviously have experience would love to hear your ideas

conorhastings avatar Jan 07 '20 00:01 conorhastings

That makes sense...seems good to me! The API changes that were made in #14 (aka #19 ) and #9 should make that API possible, I think.

Also, if it's useful this is the pattern I currently use: https://gist.github.com/jamesplease/ab7207cfd0f3aaf3ffd9990f8f4c8bed

jamesplease avatar Jan 08 '20 18:01 jamesplease

nice, definitely useful and . similar to my brain thoughts, thanks for the commentts

conorhastings avatar Jan 08 '20 19:01 conorhastings