I am trying to validate the answers from inside the parent component. The validateAnswer function gets triggered and almost works as it should.
But I want to change the site if it was validated. So I call this.props.history.push
from the parent.
And this gives me an error because history is undefined.
<Answers handleClick={e => this.validateAnswer(e)} />
//Function to validate the Answer in the parent
validateAnswer = (event) => {
if (true) {
//navigate to /email
this.props.history.push({
pathname: '/email',
state: { lastPage: 'question' },
});
//Child component
<Button
name="1"
label="Afrika"
handleClick={props.handleClick}
/>
How could I fix this? Should I validate the answer directly in the Answer component?