Design comparison
Community feedback
- @sambuka-aPosted over 1 year ago
Hi Nice solution. I would suggest that you work on loading and errors handling
Marked as helpful0@Rabiaismail21Posted over 1 year agohi @sambuka-a! Thanks for your feedback. Could you tell me how I can work on loading?
0@sambuka-aPosted over 1 year ago@Rabiaismail21 Sure You can check my solution. I used
try
catch
statement. So basically if there is an error, I can catch error object and take out it's valuemessage
. And later on I'm conditionally rendering the content. If there is an error -error.message
will be displayed and if not actually advice will be displayed.There is also
finally
statement, but you can skip it. I just wanted to play with another error when loading takes too long.//this is my React data request is try { const response = await axios.get(`https://api.adviceslip.com/advice`) setAdvice(response.data?.slip); setLoading(false) setError(null) } //if there is ae error I will catch it here to use later for conditionally rendering content catch (err) { setError(err) setLoading(false) }
Marked as helpful0
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