Design comparison
Solution retrospective
Hello, it's my first project with API. Could you tell me why I can't use 2 times then(data =>) in one Fetch? Thank you for any feedback!
Community feedback
- @DennyIsNaivePosted 12 months ago
Hey, there are a few problems with the code you wrote. First off, the quote is cached for a period of time before being removed from the cache memory, this makes it impossible to generate new quotes whenever you click on the dice. It only works once, is cached and then you have to wait for several minutes. To solve this problem, make sure no data from the api is cached or stored by explicitly defining it like so :
fetch(apiUrl, {cache: 'no-cache',})
.The next problem is that, you are fetching the same API twice. You already fetched data from the API when you first used fetch(URL) so there is no need for you to fetch the data again. You can still use the API call to define the advice number as well. Hope this helps, happy coding! XD
Marked as helpful1@ClaudioAmarenoPosted 12 months ago@DennyIsNaive Thank you for your feedback.
- I don't understand, I mean in my devices it work great, I don't have problems to generate new quotes
- I know, that's my main problem. When I used 2 times .then(data) it stopped works. I don't know why, that's why I did 2 times fetch
Edit. Ok, you had right, I just used other browser than you, now I used no-cache, and it works well. Thank you!
0@DennyIsNaivePosted 12 months ago@ClaudioAmareno Glad I could be of help. Happy coding : )
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord