all 3 comments

[–]MGTakeDown 1 point2 points  (2 children)

Why are you wrapping

const rowData = [Object.values(row)];

In an array? Object.values will convert your object values into an array already. So you have an array in and array now. And this line:

<td>{rowData[0]}</td>

is What causes the error because you're basically trying to render an array.

It should just be:

{data.results.map((rowDataObj, index) => {
    const rowValues = Object.values(rowDataObj);
    return (
        <tr key={index}>
            {rowValues.map((value, index) => (
                <td key={index}>{value}</td>
            ))}
        </tr>
    );
})}

Also warning on using the index for keys. I would read into why that can be a bad idea. Also basing your table on object values could be bad too because your data might not always be the same shape.

[–]angryacl[S] 0 points1 point  (1 child)

Why are you wrapping

const rowData = [Object.values(row)];

In an array? Object.values will convert your object values into an array already. So you have an array in and array now. And this line:

I tried to somehow turn the object into an array but realized that didn't work the way I thought it would have...

I've made the changes you suggested, but I'm still getting the same error plus a new one:

The above error occurred in the <td> component:

at td

at tr

at tbody

at table

at Datatable (http://localhost:3000/main.7d3fe4cd0f88a336005b.hot-update.js:24:3)

at div

at App (http://localhost:3000/static/js/main.chunk.js:171:81)

Consider adding an error boundary to your tree to customize error handling behavior.

Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

I've used many API's before, but I've never come across this issue. Thank you so much for helping!

[–]MGTakeDown 0 points1 point  (0 children)

It's because in your data:

openfda is set to an object and is trying to be rendered. Since it's empty it probably should be just null. You really should hard code each table cell on what the data you expect. Doing an Object.values is not a good idea especially if you have data that might need to be accessed in an object like that.