0

I am getting an error from react js when I execute this code snippet:

<TableBody>
  { (data.length > 0) ? (
    data.map((x, i) => row(
    x,
    i,
    formColumns,
    handleRemove,
    handleSelect,
    editIdx
    ))) : (<TableRow><TableCell colSpan={`${cols}`}>No Data</TableCell></TableRow>)}
</TableBody>

The value of 'data' is an empty array [], which SHOULD return a length of 0 But it passes the length test somehow.

Instead I get an error 'data.map is not a function'.

I am trying to insert:

console.log('data = ' + JSON.Stringify(data, null, 2) + '.'))

in the code somewhere, so I can see what it's doing. When I check the data GOING IN to the Table, it's = []. So why is the length not working, and what do I need to do to place javascript code inside a set of material-ui elements? Any help would be much appreciated!

1 Answer 1

0

Something like:

{ console.log('data = ' + JSON.Stringify(data, null, 2) + '.')) }

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

The problem is, I never GET to the location where you place the console.log statement. I need it BEFORE the 'row.map' line. One of the things I tried last night was to wrap the console.log in curly brackets. I STILL rec'd an error. Could you show how to put the console.log statement BEFORE the row.map (ie right after the the <TableBody> statement. This is where I get an error now matter HOW I try to frame the js statement.
Ok, then may you provide codesandbox.io with a working fragment of your code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.