This is example data coming from an API, compared to what my UI is expected (which you can find below), some of the properties are missing and breaking my UI.
let product = {
"name": "Acniben repair idratante lenitivo e riparatore",
"company": "Isdin",
"price": 16.1,
"details": {
"administration": "topica",
"format": {
"form": "gel",
},
"pathology": "Acne",
"pathologies": ["Pregnancy"]
}
}
Data format my UI is expecting:
let product = {
"name": "Isdiben",
"company": "Isdin",
"price": 13.6,
"indicators": [
"Gluten-free",
"Lactose-free",
"Nickel-free"
],
"details": {
"activeIngredient": {
"name": "isotretinoin",
"dosage": "10mg"
},
"administration": "Per os",
"class": "C",
"format": {
"form": "pill",
},
"pathology": "Acne",
"population": ["Pregnancy"]
}
}
How I tried destructuring with default values (to avoid TypeErrors):
const {
name = "N/A",
company = "N/A",
price = "N/A",
indicators = [],
details = {
activeIngredient: {
name = "N/A",
dosage = "N/A",
},
administration = "N/A",
class = "N/A",
format: {
form = "N/A",
},
pathology = "N/A",
population = [],
},
} = product;