Hooks
objectliteral opened this issue · comments
Currently, unless users want to bring the store into scope, they need to use the withState
HOC to connect their components to a store. Potentially, some users might dislike HOCs and would prefer an API that uses Hooks instead.
Suggestion: Design and implement a Hooks API (useStore
).
Details about how this API should look like and how it can be implemented are still to be decided.
The Hooks API for fleux includes four functions:
useStore
exposes the context-dependent store object. It is proxied to only trigger updates on key-changes of keys that are actually read by this component.useStore
also exposesdispatch
.useSelector
acts similar touseStore
but takes a function argument that is used as aselectStateProps
function.useDispatch
just returns thedispatch
method of the context-dependent store.useActions
exposes named actions.
As a side-comment, I want to point out how surprisingly easy it was to implement this. I am not sure as to why this is: I did not have to worry about parseProps
-stuff and the nesting of components like in the withState
implementation. Nevertheless, it feels suspicious that this was so easy.
Merged in 7d45624