score:0

Accepted answer

katia wheeler is correct. if you want to stay with the promise only. then inside you second then where you have your console.log you can use this.setstate.

fetch('https://api.github.com/users/krunallathiya')
.then(res => res.json())
.then(json => {
  this.setstate({
    graphdata: json,
  })
});

then you will have it in the component state and you can use it normally from there.

score:2

assign the response to a variable and then call setstate with the data like so:

updated with async

const response = await fetch('https://api.github.com/users/krunallathiya')
.then(res => res.json());

this.setstate({
    data: response
});

then you can access your response using this.state.data in render for the graph.


Related Query

More Query from same tag