Skip to content

Access state props in mapDispatchToProps #535

Closed
@gnapse

Description

@gnapse

I was wondering why it is not possible to access state-derived props in mapDispatchToProps. For instance, given the following mapStateToProps function:

const mapStateToProps = (state, props) => {
  return {
    quota: state.quota,
  };
};

I would like to access props.quota in the corresponding mapDispatchToProps:

const mapDispatchToProps = (dispatch, props) => {
  return {
    unlockItem(item_id) {
      if (props.quota > 0) {
        dispatch(unlockItem(item_id));
      }
    },
  };
};

And if it is possible, how. Because I tried and could not. And I could not find anything about it in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions