nathanbuchar / react-hook-thunk-reducer

📡 A React useReducer() hook whose dispatcher supports thunks à la redux-thunk.
MIT License
107 stars 14 forks source link

Expose getState #15

Closed agg23 closed 4 years ago

agg23 commented 4 years ago

There are non-dispatch scenarios where you need to grab the current value of state and waiting for it to propagate through props or context is not appropriate (say in a "save" callback). Since useThunkReducer already creates getState internally to expose to thunk functions, it would be trivial to expose getState alongside the current state and dispatch.

nathanbuchar commented 4 years ago

Hi @agg23, appreciate the idea!

However, this package is intended to be a drop-in replacement for the native useReducer hook. The idea is that it should behave exactly the same as useReducer, just with thunk support. Although adding extra features to it would be trivial (and perhaps even useful), it's not in the spirit of what this package is built to be