Charles Stover
1 min readMar 15, 2019

--

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.

--

--