I'm having problem with settings state value with a value returned from a function. Somehow, the state only bind itself to the function itself. How can I fix this?
Here is my constructor:
this.state = {
text: getText
}
Here is the function that retrieves the
getText= () => {
$.get('/webapi/gettext, function (data) {
return data;
}.bind(this));
};
but this works if I have it in the constructor.
constructor{
$.get('/webapi/gettext, function (data) {
this.setState({ text: data });
}.bind(this));
}