Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Proposal: Add trivial dispatch mapping functionality #2

Open
@raunofreiberg

Description

@raunofreiberg

Loving this library and it's simplicity so far. I'm just wondering why have you decided to exposedispatch 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
  • 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 asreturn [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 }  );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp