-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
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:
useSubstatetakes a secondary argumentactionswhich is either aobjector afunction- Based on the type, call the actions with dispatch or simply bind the actions.
const mappedActions =
typeof actions === "function"
? actions(store.dispatch)
: bindActionCreators(actions, store.dispatch);
- Return it as
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:
const [substate, actions] = useSubstate(
state => ({ count: state.count }),
dispatch => ({
increment: () => dispatch(increment()),
decrement: () => dispatch(decrement()),
})
);
or
const [substate, actions] = useSubstate(
state => ({ count: state.count }),
{ increment, decrement }
);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels