Reputation: 423
I feel like this may be an easy solution but I am having a hard time understanding on why I unable to get rid of the errors in regards to my if statement.
I am getting a number of syntax errors in regards to my if statement
if (selectedDate < new Date().toISOString().split('T')[0]) {
selectableRows: "none"
}
I've tried adding a return (selectableRows: "none") but that did not resolve my issues either.
const custom = {
customToolbar: () => <DataTableRefreshButton refresh={refresh} />,
customToolbarSelect: (selectedRows, displayData) => (
<TestToolBar
data={data}
alert={alert}
rows={rows}
type={type}
/>
),
isRowSelectable: (displayData) => {
const data= updatedStaff[
data
];
return (currentData.ActionTypeID > 0 || currentData.ActionCompletedByID > 0 ? false : true)
},
if (selectedDate < new Date().toISOString().split('T')[0]) {
selectableRows: "none"
}
};
Upvotes: 0
Views: 44
Reputation: 218847
Simplifying, you have a structure like this:
const custom = {
firstProperty: 1,
secondProperty: 'test',
if (someCondition) {
thirdProperty: 'third'
}
};
This is not valid JavaScript. You can use if
blocks when writing multiple statements, but not in the middle of setting the properties of an object.
If there's a valid default for that property, you can use the ternary conditional operator to set it:
const custom = {
customToolbar: ...
customToolbarSelect: ...
isRowSelectable: ...
selectableRows: (selectedDate < new Date().toISOString().split('T')[0]) ? 'none' : 'default'
}
Otherwise you may need to more dynamically build your object. Something like:
const custom =
(selectedDate < new Date().toISOString().split('T')[0])
? { /* properties with selectableRows */ }
: { /* properties without selectableRows */ }
Upvotes: 1