I am setting state in the constructor like this - this is for text that says "Fetching data...":
this.state = {
loading: true
}
Then I have an async function like this, which will get some data.
componentDidMount() {
this.fetchData().done()
}
async fetchData() {
const response = await fetch(URL)
const json = await response.json()
const stars = json.stargazers_count
this.setState({ stars })
}
How do I know when I can set the isLoading state to false and hide the loading text and display the data? I seem to be missing some piece here!
Thanks Jordan