I am wondering how to go about creating a data set of random quotes using an API. I have a list of websites that generate random quotes. I have tried to link to one of these websites and pull quotes with fetch(). My code is not logging any data to the console. Here is my code:
Thanks for the help! And to your criticism - nothing was “just thrown” in anywhere. It seems that I was not far from success. I tried this using classes and things are working.
I am now logging data onto my console, but I have another problem - my data variable is not able to be used when rendering JSX because componentDidMount only creates the data variable after the page is rendered. I tried changing componentDidMount to componentWillMount but the variable data still cannot be accessed, although it logs on the console from inside the async await function. Anyone have any ideas how to access my data variable?
do I do this using async and await in the onClick? Or should I use some sort of conditional to check if fetch is completed? I can’t think of how to set a state key or prop to “successful” once the fetch is successful.