React this.props is undefined
I think you're missing the following, try replacing your constructor:
constructor(props) {
super(props);
console.log(this.props)
}
Try it out, you should get output from this.props
.
The constructor for a React component is called before it is mounted. When implementing the constructor for a React.Component subclass, you should call super(props) before any other statement. Otherwise, this.props will be undefined in the constructor, which can lead to bugs. Source: ReactJS.org Component Docs.
In my case, I forgot to bind the method that I was calling, that's why props
was undefined.
constructor(props) {
super(props);
this.changeScreenToForm = this.changeScreenToForm.bind(this);
}
changeScreenToForm() {
this.props.app.changeScreen(Form);
}