My goals are to make a redirection with a BACK button, but until now no success. When i'm trying to pass a function from child to parent it return me :
_this.props.callHomeFunction is not a function
Parent.js
constructor(props) {
super(props);
this.state = {
okRedirect: false,
}
this.consoleToHome = this.consoleToHome.bind(this)
}
consoleToHome = (test) => {
// this.setState({ okRedirect: true });
console.log('go to home');
console.log(test);
}
render(){
return(
<Router>
<Select callHomeFunction={this.consoleToHome} />
Child.js
class BackButton extends Component {
changePage = () => {
const test = 'test';
console.log('click on home');
console.log(this.props);
this.props.callHomeFunction(test);
}
render() {
return (
<div className='back_buttons'>
<ul>
<li>
<button className='back_buttons back_button'
onClick={this.changePage}
>
consoleToHomeonthisas you are using an arrow function. (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…)onClick={this.changePage()}the result is the same , but this time doesnt show the next page after the HomeonClick={this.changePage}, notonClick={this.changePage()}. If the problem persists, consider updating the question with stackoverflow.com/help/mcve that reflects your current attempt.