I have react component which returns an integer. Structure of the class component is as follows:
class MyClass extends Component {
constructor(props) {
super(props);
this.state = {
variable : 0
}
}
componentDidMount(){
// do some works
this.setSate({variable:$someValue});
}
render(){
var temp = this.state.variable;
return temp;
}
}
I need to fetch the value returned from MyClass in another class component in React within render. If I call like,
render () {
return (
<div>{Myclass}</div>
);
}
it works fine. is there any way to call this outside return, and assign the value to a variable?