I have seen some similar questions to this one, but I'm not entirely sure if I understand how mapDispatchToProps, bindActionCreators and connect work and so am unsure where I'm going wrong.
At the moment, my recordFullTimeScoreAnswer function is being called, but when it enters the function nothing happens after the return line. The console.log is not printed and there aren't any errors
Component
renderNextQuestionArrow(question: Question) {
const p = this.props;
const s = this.state;
return (
<div onClick={ () => { p.recordFullTimeScoreAnswer(s.homeScore, s.awayScore, p.question, p.questionIndex, p.user, p.configs) } }>
<Arrow direction="right" action={ () => { p.showNextQuestion() } }/>
</div>
)
}
Container
import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { recordFullTimeScoreAnswer, showNextQuestion } from '../actions';
render() {
return(
<FullTimeScoreActive
imgSrc={imgSrc}
user={user}
answerStatus={answerStatus}
question={question}
showNextQuestion={showNextQuestion}
recordFullTimeScoreAnswer={recordFullTimeScoreAnswer}
questionIndex={questionIndex}
total={total}
configs={configs}
/>
)
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({ recordFullTimeScoreAnswer, showNextQuestion }, dispatch);
};
export default connect(mapStateToProps, mapDispatchToProps)(FullTimeScoreContainer);
export { FullTimeScoreContainer }
Action
export function recordFullTimeScoreAnswer(
homeScore: number,
awayScore: number,
question: Object,
questionIndex: number,
user: User,
configs: Configs
) {
console.log("outside record answer");
return (dispatch: Function) => {
console.log("inside record answer");
let uri = configs.baseAPIPath + '/questions/';
if ( user.loggedIn ) {
fetchWithAuth(uri, 'POST', answer, user.tokens, configs.clientId, dispatch, false, v.questionId).then( (data) => {
if (data) {
dispatch({
type: RECORD_ANSWER_SUCCESS,
payload: { questionIndex, answerId }
})
}
});
}
}
}
The last thing I see is the "outside record answer" log but never the "inside record answer" one