Skip to content
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

rowKey -> rowKeyGetter #2190

Merged
merged 3 commits into from
Oct 27, 2020
Merged

rowKey -> rowKeyGetter #2190

merged 3 commits into from
Oct 27, 2020

Conversation

nstepien
Copy link
Contributor

@nstepien nstepien commented Oct 27, 2020

Pros:

  • Rows can now be of any type, and we type-check that the row key is a React.Key.
  • It's a lot more flexible, it doesn't have to be a value held in the row data for example.
  • -1 generic

Cons:

  • Users must implement the function.
    • Implementations should be trivial, I think this is a non-issue
    • It's still optional, unless row selection is enabled.
  • The function should be static to avoid re-renders
    • A static function declaration outside the functional component should work, at worst users have to use useCallback.
    • Class members are still good.

@nstepien nstepien self-assigned this Oct 27, 2020
lastSelectedRowIdx.current = -1;
}

onSelectedRowsChange(newSelectedRows);
};

return eventBus.subscribe('SelectRow', handleRowSelectionChange);
}, [eventBus, isGroupRow, onSelectedRowsChange, rowKey, rows, selectedRows]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isGroupRow changes on each render, so this was unnecessary.

src/DataGrid.tsx Outdated
if (typeof rowKeyGetter === 'function') {
const rowKey = rowKeyGetter(row);
isRowSelected = selectedRows?.has(rowKey) ?? false;
if (typeof rowKey === 'string' || typeof rowKey === 'number') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still manually typecheck this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not as we are using React.Key

@nstepien nstepien marked this pull request as ready for review October 27, 2020 17:25
Copy link
Contributor

@amanmahajan7 amanmahajan7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup

src/DataGrid.tsx Outdated
if (typeof rowKeyGetter === 'function') {
const rowKey = rowKeyGetter(row);
isRowSelected = selectedRows?.has(rowKey) ?? false;
if (typeof rowKey === 'string' || typeof rowKey === 'number') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not as we are using React.Key

@nstepien nstepien merged commit 0c9a3e4 into canary Oct 27, 2020
@nstepien nstepien deleted the rowkeygetter branch October 27, 2020 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants