-
Notifications
You must be signed in to change notification settings - Fork 36
Fix missing callback dependencies #2188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -478,15 +478,15 @@ const DataTable = ({ | |||
|
|||
const convertColumnToFilter = useCallback( | |||
(column: DataTableColumn<DataTableRowData>) => | |||
column.enableColumnFilter && column.accessorKey | |||
column.enableColumnFilter !== false && column.accessorKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is enableColumnFilter
a boolean
? Not sure we'd need to be this specific here. Unless there is some context I am missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is part of material-react-table
(right?), or I'd make a comment about is
or has
prefixes.
I also agree with @bryancunningham-okta. Why not this instead?
column.enableColumnFilter !== false && column.accessorKey | |
!column.enableColumnFilter && column.accessorKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming from Material-React-Table. In a column definition, if you set enableColumnFilter
to false
, a filter won't display for that column.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess what I'm getting at is, enableColumnFilter
is either truthy or falsey right? Can just be this
column.enableColumnFilter && column.accessorKey
return accumulator.concat(filter); | ||
} | ||
} | ||
} else if ("accessorKey" in item) { | ||
// Checks if it's a column | ||
const filter = convertColumnToFilter(item); | ||
if (filter) { | ||
accumulator.push(); | ||
return accumulator.concat(filter); | ||
} | ||
} else if ("label" in item) { | ||
// Checks if it's a DataFilter | ||
accumulator.push(item); | ||
return accumulator.concat(item); | ||
} | ||
// If none of the conditions match, item is ignored (not mapping to undefined) | ||
return accumulator; | ||
}, []); | ||
}, [columns, filtersProp]); | ||
}, [columns, filtersProp, convertColumnToFilter]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* refactor: replace push with concat * refactor: fix missing dependencies * fix: fix broken filters
Fixes a few missing dependencies in
useCallback
anduseMemo
, and replaces.push()
with.concat()
as per Kevin's suggestion.