ReactJS – React-Redux: Can’t find MapDispatchToprops

My impression is that the methods added to mapDispatchToProps should be accessible by this.props. When I call these methods, it will raise “Uncaught TypeError: this.props.onHighlight is not Function”.
Does anyone know what happened? I have been trying a bunch of different alternatives for mapDispatchToProps, but none of them work.

import React from'react';
import {addHighlight , deleteHighlight, selectHighlight} from'actions/highlight';
import {connect} from'react-redux';
import jquery from'jquery';
import {styles} from'./ styles.scss';

const mapDispatchToProps = dispatch => {
return {
onHighlight: (start, end, selectedText) => {
dispatch(addHighlight( start, end, selectedText));
},
onDeleteHighlight: (source) => {
dispatch(deleteHighlight(source));
},
onSelectHighlight: (source) => {
dispatch(selectHighlight(source));
}
};
}

const mapStateToProps = state => {< br /> return {highlights: state.highlights,
currentTopic: state.currentTopic,
selectedHighlight: state.selectedHighligh t,};
}

...
Other code about Highlight object
...

export default connect(
mapStateToProps,
mapDispatchToProps
)(Highlight);

try it bindActionCreators:

import {bindActionCreators} from'redux'

const mapDispatchToProps = dispatch => {
return bindActionCreators({
onHighlight: addHighlight,
onDeleteHighlight: deleteHighlight,
onSelectHighlight: selectHighlight
}, dispatch);
}

< p>My impression is that the methods added to mapDispatchToProps should be accessible by this.props. When I call these methods, “Uncaught TypeError: this.props.onHighlight is not a function” is raised.
Does anyone know what happened? I have been trying a bunch of different alternatives for mapDispatchToProps, but none of them work.

import React from'react';
import {addHighlight , deleteHighlight, selectHighlight} from'actions/highlight';
import {connect} from'react-redux';
import jquery from'jquery';
import {styles} from'./ styles.scss';

const mapDispatchToProps = dispatch => {
return {
onHighlight: (start, end, selectedText) => {
dispatch(addHighlight( start, end, selectedText));
},
onDeleteHighlight: (source) => {
dispatch(deleteHighlight(source));
},
onSelectHighlight: (source) => {
dispatch(selectHighlight(source));
}
};
}

const mapStateToProps = state => {< br /> return {highlights: state.highlights,
currentTopic: state.currentTopic,
selectedHighlight: state.selectedHighlight,} ;
}

...
Other code about Highlight object
...

export default connect(
mapStateToProps ,
mapDispatchToProps
)(Highlight);

Try to use bindActionCreators:

import {bindActionCreators} from'redux'

const mapDispatchToProps = dispatch => {
return bindActionCreators({
onHighlight: addHighlight,
onDeleteHighlight: deleteHighlight ,
onSelectHighlight: selectHighlight
}, dispatch);
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5936 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.