A
A
Alexander2018-11-24 16:56:33
React
Alexander, 2018-11-24 16:56:33

How to pass a separate action in redux to mapDispatchToProps?

You need to pass an asynchronous action(redux-thunk) to the second argument of the connect function.
In the documentation I saw only examples of how to pass actions as an imported module, but I don’t understand how to pass them as a separate function

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-01
@aleksand44

import { myAsyncAction } = this.props;

/ * ... * /

const mapDispatchToProps = {
  myAsyncAction,
};

export default connect(mapStateToProps, myAsyncAction)(MyComponent);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question