table: Cannot read property 'className' of undefined
I get this error and it’s located in the utils.js file:
function splitProps(_ref2) {
var className = _ref2.className, //<---here
style = _ref2.style,
rest = _objectWithoutProperties(_ref2, ['className', 'style']);
return {
className: className,
style: style,
rest: rest
};
}
I understand that it has something to do with my column headers, so here is (sort of) my columns definition:
columns: [
{
header: 'Sections',
columns: [{
header: 'Section',
accessor: 'sectionName',
sortable: false
}, {
header: 'Sub-Section',
accessor: 'subSectionName',
sortable: false
}]
},
{
header: 'KPIs',
columns: [{
header: 'KPI',
accessor: 'kpiName_1',
minWidth: 200,
sortable: false,
render: props => <span>{props.row && props.row.kpiName_2 ? '' : props.value}</span>
}, {
header: 'Sub-KPI',
accessor: 'kpiName_2',
minWidth: 140,
sortable: false,
render: props => <span>{props.row && props.row.kpiName_3 ? '' : props.value}</span>
//more columns like that
}]
},
{
header: 'Details',
columns: [{
// more columns here
header: 'NO',
accessor: 'kpiNumber',
render: rowInfo => <span>{rowInfo.value}</span>,
width: 50,
sort: 'asc' //i know, but that is still the only way sorting works for me, @5.3.4
}]
},
{
header: () => <span>{this.props.selectedYear}</span>,
columns: [{
header: 'Apr',
id: 'april',
accessor: data => data.months && data.months.length > 0 && data.months[3].value,
width: 70,
sortable: false,
render: ({index, value, row, aggregated}) => this.handleMonthValuesRender(index, value, row, aggregated, 3)
},{
// more columns
}]
}
]
I tried removing all grouped headers but didn’t fix the issue.
Any help is much appreciated, maybe I have to check something different than the columns too, I don’t know.
EDIT: To be more specific, probably the problem is with my code and not react-table, so I would like to know what causes this error.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19
I had this problem as well. Same error code, and I narrowed the issue down to gettrbyprops. Turns out I didn’t have a return. I had a return in my if statement: if (rowInfo && rowInfo.row)
…but if that if statement failed there was no return. I just returned an empty object and it works now, which makes sense. Hopefully this helps.
I had this issue when testing a component which rendered a react-table. I’m was just sending in the function
() => {}to getTrProps to then spy on the function to see if it had been called. I don’t need it to do anything.Anyway, I got the error that OP got, and had to change the function to
() => ({})for it to return something.