Fetching Data from an API
Our app fetches jokes from the JokeAPI using the browser’s fetch function. A typical fetch call looks like:
fetch("https://sv443.net/jokeapi/v2/joke/Any?type=single")
.then(res => res.json())
.then(data => setJoke(data.joke));This sends an HTTP GET request to the API. When the JSON response arrives, we extract the joke text and update the joke state. (See a similar example of fetching from the JokeAPI.) This asynchronous API call happens inside our fetchJoke function and ensures the UI shows the latest joke.


