@fazzaamiarso
Posted
Hi @suhjiwon95! Great work!
I have some quick tips for you
- To improve user experience, you can fetch an initial advice so the UI doesn't feel empty. You can also insert an Empty State UI.
- When naming in Javascript, especially Frontend, it's primary convention is to use camelCase. If I'm not mistaken, snake_case is Python's convention.
const advice_id = data.slip.id;
const adviceId = data.slip.id; 👍
- You can also do Object destructuring.
const { advice } = data.slip;
I hope it helps! Cheers!
Marked as helpful
@suhjiwon95
Posted
Thank you for your suggestion! @fazzaamiarso
What exactly the object destructuring will do?
@fazzaamiarso
Posted
@suhjiwon95 It's essentially extracting properties of an Object. It's also more efficient when you want to get multiple properties from an Object. You can also destructure an Array.
// example object
const person = { firstName : "John", lastName : "Smith", age : 23, country : "USA" } }
// use destructuring
const { firstName, lastName } = person; ✅
// 😮💨 can be tedious to re-assign
const firstName = person.firstName;
const lastName = person.firstName;
A common use case is to extract a Component's Props in React. Here's a more comprehensive guide
I hope it answers your question!
Marked as helpful
@suhjiwon95
Posted
Wow this is far more advanced JS for me at this point 🤣 But I will definitely check it out! @fazzaamiarso