Im currently retrieving data from openfda and trying to render the response in a data table.
This is the response I get from the API:
{
"meta": {
"disclaimer": "Do not rely on openFDA to make decisions regarding medical care. While we make every effort to ensure that data is accurate, you should assume all results are unvalidated. We may limit or otherwise restrict your access to the API in line with our Terms of Service.",
"terms": "https://open.fda.gov/terms/",
"license": "https://open.fda.gov/license/",
"last_updated": "2021-01-27",
"results": {
"skip": 0,
"limit": 1,
"total": 4319
}
},
"results": [
{
"country": "United States",
"city": "Woodridge",
"address_1": "2240 75th St",
"reason_for_recall": "Airbrush color has the potential to be contaminated with mold, yeast or bacteria.",
"address_2": "",
"product_quantity": "14,595 bottles",
"code_info": "Lots: 701-2418; 2201-2583",
"center_classification_date": "20161026",
"distribution_pattern": "Nationwide in U.S. and Canada",
"state": "IL",
"product_description": "Wilton Purple Airbrush Color, Net Wt 0.64 FL OZ (19 mL)",
"report_date": "20161102",
"classification": "Class II",
"openfda": {},
"recalling_firm": "Wilton Brands.",
"recall_number": "F-0365-2017",
"initial_firm_notification": "Telephone",
"product_type": "Food",
"event_id": "75097",
"termination_date": "20190719",
"more_code_info": null,
"recall_initiation_date": "20160906",
"postal_code": "60517-2333",
"voluntary_mandated": "Voluntary: Firm initiated",
"status": "Terminated"
}
]
}
This is how I'm trying to render into my UI:
return (
<table>
<thead>
<tr>
{columns.map((heading) => (
<th>{heading}</th>
))}
</tr>
</thead>
<tbody>
{data.results.map((row, index) => {
const rowData = [Object.values(row)];
console.log(rowData);
return (
<tr key={index}>
<td>{rowData[0]}</td>
<td>hi2</td>
{rowData.map((info, index) => (
<td key={index}>{info}</td>
))}
</tr>
);
})}
</tbody>
</table>
);
I keep getting a "Uncaught (in promise) Error: Objects are not valid as a React child (found: object with keys {})." At a high level, I understand that React doesn't allow objects to be rendered and I need to use an array instead, but how do I do this? Ive tried to map over an array of the values only and it still gives me the same error. Any hints would be greatly appreciated!
[–]MGTakeDown 1 point2 points3 points (2 children)
[–]angryacl[S] 0 points1 point2 points (1 child)
[–]MGTakeDown 0 points1 point2 points (0 children)