react-excel-renderer icon indicating copy to clipboard operation
react-excel-renderer copied to clipboard

TypeError: Cannot read property 'map' of undefined

Open avinashstunts123 opened this issue 5 years ago • 3 comments

i am getting json data from excel file. but when i use outtabele i am getting this error _**TypeError: Cannot read property 'map' of undefinedpai files

**_

avinashstunts123 avatar May 14 '19 12:05 avinashstunts123

@avinashstunts123 were you able to solve this issue??

iam1208 avatar Jul 08 '19 10:07 iam1208

I just saw this error in my app. In my case the problem was here:

ExcelRenderer(file, (error: Error, response: any) => {
  if (error) {
    console.error(error);
  } else {
    setRows(response.rows);
    setColumns(response.columns); // <-- here's what's wrong
  }
})

The correct property is response.cols, not response.columns, so I was writing undefined to into state instead of the actual columns data. Hence the inability for React to read the .map() method from what should have been an array but was in fact undefined.

glassblowerscat avatar Jul 22 '20 21:07 glassblowerscat

Hello , sorry for my english i resolve this, it's work for me .

`

const [cols,setCols]=useState([]); const [rows,setRows]=useState([]);

const fileHandler = (event) => {
    let fileObj = event.target.files[0];

    //just pass the fileObj as parameter
    ExcelRenderer(fileObj, (err, resp) => {
        if(err){
            console.log(err);
        }
        else{

                setCols(resp.cols)
                setRows(resp.rows)

        }
    });

}

return (
    <div>
    <input type="file" onChange={fileHandler.bind()} style={{"padding":"10px"}} />

<OutTable data={rows} columns={cols} tableClassName="ExcelTable2007" tableHeaderRowClass="heading" />
    </div>
)

`

I configure useState with empty Array.

cangui2 avatar Feb 02 '21 08:02 cangui2