I am using react native-redux to set global state and it works fine when handling single data but when I have multiple data its not working. Below is my code:
import {connect} from 'react-redux'
constructor(props){
super(props)
this.state = {
comment:'',
region:[],
}
}
<Button
onPress={() => {
this.setState({
comment : this.state.comment,
// works fine if I only handle comment or region
region : this.state.region,
},
() => this.props.commentHandler(this.state),
() => this.props.regionHandler(this.state)}}>
<Text>UPDATE</Text>
</Button>
function mapStateToProps(state) {
return {
comment : state.comment,
region : state.region
}
}
function mapDispatchToProps(dispatch) {
return {
commentHandler : (state) => dispatch({ type: 'COMMENT', payload: state.comment}),
regionHandler : (state) => dispatch({ type: 'REGION', payload: state.region})
}
}
I don't know what I did wrong but when I try to handle multiple data for example, comment & region it won't work. It works perfectly if I remove () => this.props.commentHandler(this.state) or () => this.props.regionHandler(this.state) but doesn't work together.
Any idea what I might be doing wrong? Any comments or advise would be really appreciated!
this.props.region,this.props.commentin the next screen, it will only display the first state which isthis.props.commentthe other one will be undefined any idea why?