This is the original data:
const myArray = [
'id': 'stuff', 'location': 'stuff2',
'phone_numbers'['stuff3','stuff4'], "address" : 'stuff5'
]
// so far, I'm getting the correct values back in an array from an API.
console.log(myReturnedArray) = [
{
"id": "10001",
"brand": "Best Brand",
"center_name": "Best Brand Texas",
"status": "Active",
"emails": [
{
"CreateDate": "October 12, 2022 at 10:59:09 AM UTC-5",
"emailAddress": "[email protected]",
"firstName": "Test",
"lastName": "Tester",
"id": "0eac8839-6e61-42f5-b55f-e2fa17b0262b",
"licenseType": "Unlimited",
"updateDate": "October 12, 2022 at 10:59:09 AM UTC-5",
"userType": "STORE"
}
],
"licenses": [
{
"CreateDate": "October 12, 2022 at 10:59:09 AM UTC-5",
"licenseType": "STORE",
"status": "ASSIGNED",
"updatedBy": "SYSTEM",
"updateDate": "October 12, 2022 at 10:59:09 AM UTC-5",
"renewDate": "October 12, 2022 at 10:59:09 AM UTC-5",
"expirationDate": "October 12, 2022 at 10:59:09 AM UTC-5",
"id": "0eac8839-6e61-42f5-b55f-e2fa17b0262b"
}
]
}
]
*** whenever i try a map function i get the error "Objects are not valid as a React child (found: object with keys {id, brand, center_name, status, emails, licenses}). If you meant to render a collection of children, use an array instead." ***
I would like to display each value from my returned array in a div or span, but I keep getting errors like cannot get properties of undefined reading map, or a unique keys error whenever I try something.
// I would like to have each value from the object inside of myReturnedArray to use in my return statement.
return (
<span>your email is : "[email protected]", </span>
<div> your first name is : "Test" </div>
<span> your last name is : "lastName": "Tester", </span>
);
Anytime I try and use a map function like this in my return statement:
{ myReturnedArray.map(item => <div>{item.name}</div>) }
It returns myReturnedArray is undefined. But when I do:
{ JSON.stringify(myReturnedArray) }
It renders returnedArray as a string correctly. So I know the return method has access to the array; I just can't display it.
myArraylooks pretty messed up. Are you sure that is the correct format that is being returned by your database?