How does connect takes in mapStateToProps and mapDispatchToProps to create a higher order component?
up vote
0
down vote
favorite
I've been trying to figure out two things regarding redux
mpaDispatchToProps
is a function that takes indispatch
as an argument, where isdispatch
defined? and- how does
connect
utilizemapStateToProps
andmapDispatchToProps
to create HOC(Higher Order Component) ?
If I understand correctly, connect is essentially a compositional function that takes the result of mapDispatchToProps
and passes it to mapStateToProps
then return the result, which is a component, but how is it done?
Thank you for your time!
redux react-redux
add a comment |
up vote
0
down vote
favorite
I've been trying to figure out two things regarding redux
mpaDispatchToProps
is a function that takes indispatch
as an argument, where isdispatch
defined? and- how does
connect
utilizemapStateToProps
andmapDispatchToProps
to create HOC(Higher Order Component) ?
If I understand correctly, connect is essentially a compositional function that takes the result of mapDispatchToProps
and passes it to mapStateToProps
then return the result, which is a component, but how is it done?
Thank you for your time!
redux react-redux
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've been trying to figure out two things regarding redux
mpaDispatchToProps
is a function that takes indispatch
as an argument, where isdispatch
defined? and- how does
connect
utilizemapStateToProps
andmapDispatchToProps
to create HOC(Higher Order Component) ?
If I understand correctly, connect is essentially a compositional function that takes the result of mapDispatchToProps
and passes it to mapStateToProps
then return the result, which is a component, but how is it done?
Thank you for your time!
redux react-redux
I've been trying to figure out two things regarding redux
mpaDispatchToProps
is a function that takes indispatch
as an argument, where isdispatch
defined? and- how does
connect
utilizemapStateToProps
andmapDispatchToProps
to create HOC(Higher Order Component) ?
If I understand correctly, connect is essentially a compositional function that takes the result of mapDispatchToProps
and passes it to mapStateToProps
then return the result, which is a component, but how is it done?
Thank you for your time!
redux react-redux
redux react-redux
asked 19 hours ago
Michael Cheng
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
mapDispatchToProps
is a function that you will define. React-Redux calls your function withdispatch
passed in as the first parameter. And thatdispatch
, in turn, comes from thestore
you provided to<Provider />
.
connect
takes themapState
andmapDispatch
that you will define, and create the wrapper function that, in the most common cases:
- run
mapState
withstate
every time your store changes - run
mapDispatch
once when the component is instantiated
The returns of both of these functions will be merged into your wrapped component.
- run
Seems that you'd like to figure out how it is done. This Dan Abramov's gist explains connect
in a mental modal (simplified version of what it does).
Hope that helps!
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
mapDispatchToProps
is a function that you will define. React-Redux calls your function withdispatch
passed in as the first parameter. And thatdispatch
, in turn, comes from thestore
you provided to<Provider />
.
connect
takes themapState
andmapDispatch
that you will define, and create the wrapper function that, in the most common cases:
- run
mapState
withstate
every time your store changes - run
mapDispatch
once when the component is instantiated
The returns of both of these functions will be merged into your wrapped component.
- run
Seems that you'd like to figure out how it is done. This Dan Abramov's gist explains connect
in a mental modal (simplified version of what it does).
Hope that helps!
add a comment |
up vote
0
down vote
mapDispatchToProps
is a function that you will define. React-Redux calls your function withdispatch
passed in as the first parameter. And thatdispatch
, in turn, comes from thestore
you provided to<Provider />
.
connect
takes themapState
andmapDispatch
that you will define, and create the wrapper function that, in the most common cases:
- run
mapState
withstate
every time your store changes - run
mapDispatch
once when the component is instantiated
The returns of both of these functions will be merged into your wrapped component.
- run
Seems that you'd like to figure out how it is done. This Dan Abramov's gist explains connect
in a mental modal (simplified version of what it does).
Hope that helps!
add a comment |
up vote
0
down vote
up vote
0
down vote
mapDispatchToProps
is a function that you will define. React-Redux calls your function withdispatch
passed in as the first parameter. And thatdispatch
, in turn, comes from thestore
you provided to<Provider />
.
connect
takes themapState
andmapDispatch
that you will define, and create the wrapper function that, in the most common cases:
- run
mapState
withstate
every time your store changes - run
mapDispatch
once when the component is instantiated
The returns of both of these functions will be merged into your wrapped component.
- run
Seems that you'd like to figure out how it is done. This Dan Abramov's gist explains connect
in a mental modal (simplified version of what it does).
Hope that helps!
mapDispatchToProps
is a function that you will define. React-Redux calls your function withdispatch
passed in as the first parameter. And thatdispatch
, in turn, comes from thestore
you provided to<Provider />
.
connect
takes themapState
andmapDispatch
that you will define, and create the wrapper function that, in the most common cases:
- run
mapState
withstate
every time your store changes - run
mapDispatch
once when the component is instantiated
The returns of both of these functions will be merged into your wrapped component.
- run
Seems that you'd like to figure out how it is done. This Dan Abramov's gist explains connect
in a mental modal (simplified version of what it does).
Hope that helps!
answered 8 mins ago
wgao19
16615
16615
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370881%2fhow-does-connect-takes-in-mapstatetoprops-and-mapdispatchtoprops-to-create-a-hig%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown