I have been having trouble with callbacks in reactjs with web3. In the code below my alert function is properly printing the number of players returned by my contract but otherFuction is not being called and setState is not changing the value printed in my paragraph.
class PracticeComponent extends Component {
constructor(props) {
super(props);
this.state = {players: ""};
}
componentWillMount(){
simpleContract.methods.getPlayerNumber().call(function(error, result){
alert(result);
this.otherFunction(result);
});
}
otherFunction(value){
this.setState({
players:value
});
}
render() {
return (
<div>
<p> {this.state.players} <p/>
</div>
);
}
In previous attempts at a solution I have appended
simpleContract.methods.getPlayerNumber().call()
with
.then(this.otherfunction)
but have not had luck.
Any thoughts? Any pointers?