Returning A Value In A Promise
I am trying to return a String value to display it in my HTML. In my HTML, I'm using a Text element in a View (similar to a div in React Native) and try to fill it with that that I
Solution 1:
First of all return the promise chain from the method:
returnPromise.all(fetches).then(res => {
but then it still returns a promise resolving somewhen to a text, and there is no way to change that. Instead that text should be part of the components state, so that xou can update the text when the promise resolves:
onComponentDidMount() {
this._getCategories().then(categories =>this.setState({ categories }));
}
And inside render()
just do:
<div>
{this.state.categories || <Text>Loading categories</Text>}
</div>
Post a Comment for "Returning A Value In A Promise"