React, you need to use the function in the form of a function in the form of the function.
Examples are as follows:
<divlick = {() => {handlechangepage (page, totalPage)}}> change a batch </div>
Note that you cannot write c nclick directly = handlechangepage (page, totalPage), write in the new function
onClick={() => { handleChangePage(page, totalPage)
Action part corresponding code
const mapDispatchToProps = (dispatch) => {
return {
handleChangePage(page, totalPage) {
if (page < totalPage) {
dispatch(actionCreators.changePage(page + 1));
} else {
dispatch(actionCreators.changePage(1));
}
}
}
}
actionCreators
export const changePage = (page) => ({
type: constants.CHANGE_PAGE,
page
});
reducer
export default (state = defaultState, action) => {
switch (action.type) {
...
case constants.CHANGE_PAGE:
return state.set('page', action.page);
default:
return state;
}
}