-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
feat(useTable): selection manager to avoid calling multiple hooks #24377
Conversation
Implements a `createSelectionManager` function to manage selection state independently of react and avoids calling state hooks twice on each render
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 463d1b9:
|
📊 Bundle size reportUnchanged fixtures
|
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: 06dfea83bd8c002e8219b97ab0f3deecc1365e37 (build) |
Perf Analysis (
|
Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
---|---|---|---|---|---|
Avatar | mount | 1488 | 1493 | 5000 | |
Button | mount | 1124 | 1130 | 5000 | |
FluentProvider | mount | 1861 | 1852 | 5000 | |
FluentProviderWithTheme | mount | 751 | 745 | 10 | |
FluentProviderWithTheme | virtual-rerender | 688 | 697 | 10 | |
FluentProviderWithTheme | virtual-rerender-with-unmount | 741 | 738 | 10 | |
MakeStyles | mount | 2277 | 2249 | 50000 | |
SpinButton | mount | 2923 | 2991 | 5000 |
packages/react-components/react-table/src/hooks/useSelection.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-table/src/hooks/selectionManager.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-table/src/hooks/selectionManager.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-table/src/hooks/selectionManager.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-table/src/hooks/selectionManager.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-table/src/hooks/selectionManager.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-table/src/hooks/selectionManager.ts
Outdated
Show resolved
Hide resolved
const [selectionManager, setSelectionManager] = React.useState(() => | ||
createSelectionManager(selectionMode, setSelected), | ||
); | ||
|
||
return selectionMode === 'multiselect' ? multipleSelectionState : singleSelectionState; | ||
React.useEffect(() => { | ||
if (prevSelectionMode !== selectionMode) { | ||
setSelectionManager(createSelectionManager(selectionMode, setSelected)); | ||
} | ||
}, [selectionMode, prevSelectionMode]); |
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.
not blocking: Let's pair on creating useSingletone
or something like that as people who are not aware about Strict mode issues will be confused.
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.
yeah we even have a task for it, but not sure how much of a priority 18 is yet #24085
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.
LGTM
Implements a
createSelectionManager
constructor to manage selection stateindependently of react and avoids calling state hooks twice on each
render
Addresses #24226