Questions tagged [mapdispatchtoprops]
13 questions
425
votes
6 answers
What is mapDispatchToProps?
I was reading the documentation for the Redux library and it has this example:
In addition to reading the state, container components can dispatch actions. In a similar fashion, you can define a function called mapDispatchToProps() that receives…

Code Whisperer
- 22,959
- 20
- 67
- 85
49
votes
3 answers
mapStateToProps vs mapDispatchToProps
What's the difference between mapStateToProps and mapDispatchToProps arguments to the connect function in react-redux?

Lex V
- 1,414
- 4
- 17
- 35
1
vote
2 answers
mapDispatchToProps type challenge (typescript react-redux)
I am not able to figure out the type of my mapDispatchToProps. Check below in the SignInComponent const mapDispatchToProps.
Seems simple as the functions takes signIn() as a parameter, from whom type I have availble. However I was not able to figure…

rustyBucketBay
- 4,320
- 3
- 17
- 47
1
vote
0 answers
React + Redux binding child component methods to parent or keep them on their own
We have an react redux appl. We have a parent class bound to redux
It is our parent class:
render() {
return (
..
const mapStateToProps = (state, ownProps) => ({
parentRelatedFooVar: state.parentRelatedFooVar
})
const…

benchpresser
- 2,171
- 2
- 23
- 41
0
votes
1 answer
How to replace - mapDispatchToProps to useDispatch - REACT REDUX
I am a beginner in Redux - I need to replace mapStateToProps and mapDispatchToProps to hooks.
I've replaced mapStateToProps to useSelector, but I'm having trouble replacing mapDispatchToProps to hook useDispatch.
The code I attach below shows what I…

Yerba Mate
- 113
- 2
- 9
0
votes
1 answer
React Redux - mapDispatchToProps called for every event in a map function
Within my component I have a 'OnClick' handler that is supposed to fire a function called 'onSelectProject' within mapDispatchToProps that dispatches actions to the store. In this case it passes the id of the project passed from the click event
The…

Jebathon
- 4,310
- 14
- 57
- 108
0
votes
2 answers
React native app performance on connect(mapStateToProps, mapDispatchToProps)
I'm creating react native app with redux state management. I want to know what is the best practice of having connect(mapStateToProps, mapDispatchToProps).
I have several component classes i.e. ParentA, ChildA, ChildB. Currently I'm getting state…

John Stuart
- 950
- 5
- 11
- 28
0
votes
2 answers
Why is the Redux store state variable a function also or did I miss something here
I am learning React and JavaScript.
I have this Redux Store that looks like this very simple:
const initialState = {
booksList: [],
progress: false,
faild: "",
log: ""
};
When I do mapStateToProps to my Component then I don't get a log=''…

Kid
- 1,869
- 3
- 19
- 48
0
votes
2 answers
Question about mapDispatchToProps and bindActionCreators when multipla actions
I learn React Redux and reading here about using mapDispatchToProps and bindActionCreators
It works fine the bindActionCreators when using it alone like so:
export default connect(null, (dispatch) =>
bindActionCreators(actionCreators,…

Kid
- 1,869
- 3
- 19
- 48
0
votes
1 answer
react-redux current props value
I've three buttons on the page, and when clicking on any button i want to get that selected value from the store filtered by id(done in reducer). I'm trying to use redux with mapStateToProps and mapDispatchToProps pattern, but looks like when i try…

user212223
- 1
- 1
- 3
0
votes
1 answer
I cant get Redux action to work there is some error I cant spot please advice
I cant find what I do wrong but the action saveUser is imported and the mapDispatchToProps looks like it linking the actioncorrect but still I get this error
(Below after this code there is the action code)
The mapDispatchToProps is linking the…

Kid
- 1,869
- 3
- 19
- 48
0
votes
11 answers
React & Redux: State of component is not updating even with mapStateToProps
I posted an answer below, but if someone can explain why this is necessary you'll get the bounty, I went through a redux tutorial and feel like I didn't learn about mapDispatchToProps, only mapStateToProps. If you can explain at a deeper level what…

Sam
- 1,765
- 11
- 82
- 176
0
votes
1 answer
OnClick event in React not working in child component
I read "Learning React" (Alex Banks and Eve Porcello) and try to write a simple Color Organizer App not like in a book.
Presently I have such a code structure in StarRating component.
import React from "react";
import Star from…

dukalis945
- 25
- 2