the handling of reducers seems like it could be both enhanced and simplified…

It’s definitely an area I would like to improve.

Reusing the same method for two completely different purposes seems unnecessary. The reducer format requires a different argument type, and has a different return signature.

I disagree with this. The fact that it’s a different argument type and return signature is why it’s so possible. There is no reason that useGlobal(() => {}) should try to use () => {} as the property of an object/Map. I don’t think method overloading is a bad thing.

Plus, if using a ‘named reducer’, there cannot be a real data-key with the same ‘name’ as the reducer, else the app breaks!

This is definitely less than ideal that reducers and properties share a namespace. Your solution for useGlobalReducer is great, but it runs into the same issue with class Components — the reducers property cannot be assigned as a state variable. I will strongly consider just using this.dispatchGlobal.reducerName() or something to that effect.

Senior front end engineer / charlesstover.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store