W
W
WarriorKodeK2018-06-02 13:03:21
React
WarriorKodeK, 2018-06-02 13:03:21

What is mapDispatchToProps?

Hello. I do not fully understand why mapDispatchToProps is needed.
Let's say I have an action. In this action, I have an action creator and a function that does dispatch.
I import that function (which does the dispatch) into the component and call it at the right moment.
Please explain with a small example if possible.
UPD:
After watching this video and reading the comment from Anton Spirin , everything became clear, thanks!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-06-02
@WarriorKodeK

This is the object or function passed to connect as the second argument.
If you pass an AC object as the second argument to connect, then connect wraps your ACs in a wrapper function () => store.dispatch(AC) and passes it to the component's props. If you pass a function as the second argument, connect executes it, passing store.dispatch as the first argument, the component's second props, and passes the execution result to the component's props. All.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question