-
Notifications
You must be signed in to change notification settings - Fork 1
Proposal: Add trivial dispatch mapping functionality #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
dispatch
mapping functionality
Hey Rauno! I don't think that action creator are a big improvement given that we would need to create them in the same function where we'd use them. For React Redux, those make more sense since the component itself does not need to be aware of Redux at all and can just call arbitrary props. However with this hook, the component is already aware that Redux is used so I don't think you would save a lot when creating action creators. You can of course |
I'd think that the separation of concerns still applies in this case, regardless of the implementation being a hook rather than a HOC. I still feel like when comparing the following two examples, the first one makes much more sense when thinking about where certain actions from. Especially if hooks are designed to sort of be called on the top level, I think having a proper mapping of dispatch to actions would really provide more encapsulated code. Also, I'm not sure if there is a performance difference between declaring the action creators inside the hook vs. inline in the component?
Thanks! |
Loving this library and it's simplicity so far. I'm just wondering why have you decided to expose
dispatch
directly instead of adding some trivial mapping of dispatch.What I would love to see is:
useSubstate
takes a secondary argumentactions
which is either aobject
or afunction
return [substate, mappedActions];
Would love to hear your feedback on this :-) This doesn't seem to complicate the implementation that much and just allows you to write out your actions directly in the hook itself.
E.g:
or
The text was updated successfully, but these errors were encountered: