Reputation: 423
Upon start of my project I get an error stating TypeError: Cannot read property 'ActionType' of undefined
this only happens when I open the project for the first time. When I refresh the page the error goes away and does not come back.
const details = {
ActionType: currentData.ActionType,
RequestedByName: currentData.RequestedByName
}
{
name: "",
label: "",
options: {
filter: false,
sort: false,
customBodyRender: (value, tableMeta) => {
const currentData= opt [
tableMeta.rowIndex
];
const details = {
ActionType: currentData.ActionType,
RequestedByName: currentData.RequestedByName
}
return (
currentData.ActionTypeID === 0 || currentData.ActionCompletedByID > 0 ? null :
<Icon>
<Modal
details = {details}>
</Modal>
</Icon>
)
}
}
},
Upvotes: 0
Views: 119
Reputation: 36
Chances are the first time it is happening your data is still undefined but after that its cached so your results are fine - try short circuiting this by using a ternary such as ActionType: currentData ? currentData.ActionType : []
Upvotes: 0
Reputation: 27811
Check the value of the opt
array, specifically, opt[tableMeta.rowIndex]
(either add a console.log
or a breakpoint). Chances are that value is undefined
the first time you access the page, and therefore accessing a property on it causes an error.
I suggest adding an if(currentData)...
condition, before assigning to details
.
Upvotes: 1