I have a component defined like this
export class A extends Component{
constructor(props){
this.state = {
scene:0
}
}
static changeScene(scene){
this.setState({scene:scene})
}
}
I want to call change scene from anywhere using A.changeScene(sceneVal)
to change the scene in A. the problem is i can't access this.setState i got this error Unhandled JS Exception: this.setState is not a function.
I am sure that the A component is already mounted. I can bypass this error by defining a global variable var self = null; and inside the constructor self = this in the constructor but i want a better way to rosolve this problem
A? If yes, then assigningthisto a static variable seems reasonable. If not, then then you need to rethink the question.bindto keep the context. You could give it a trythisyour non static functions have access to. Think about non-static methods, as each instance have it, and think about static methods as the class has it.