Design comparison
Solution retrospective
~~ Feedback Please ☕👌🏻
Community feedback
- @thevolcanomanisherePosted about 2 years ago
Hi Gustavo,
Great work. The design is on-point. For your Javascript, I have some suggestions: https://github.com/GugaS1lva/Fr.Mentor-11--Advice_Generator-App/blob/main/pages/index.js
You should create a single function that wraps the fetch call, so that you are not writing out the same function multiple times. This is called DRY (dont repeat yourself). Maybe a "getAdvice" function. On line, 45, you can then reuse this function instead of writing it out again. It is also good practice not to write out new functions inside of your component. You should always write your functions above your components. This helps to organise things a little easier.
You don't need 2 different useStates. You can use a single useState like const [data, setData] = useState("Loading..."); You then have access to the id and advice either by creating a simple selector or de-structuring the object. You can put data.slip into advice, then you can access with data.id and data.advice. :)
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