Skip to content

Commit dd76e81

Browse files
authored
Remove prevSelectedPosition state (#3627)
* Remove `prevSelectedPosition` state and one `useLayoutEffect` * `lodash` is not used * Add back `useLayoutEffect`
1 parent ff441ba commit dd76e81

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

eslint.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,6 @@ export default [
574574
{
575575
name: '@testing-library/dom',
576576
message: 'Import @testing-library/react instead.'
577-
},
578-
{
579-
name: 'lodash',
580-
message: 'Import lodash-es instead.'
581577
}
582578
],
583579
'@typescript-eslint/no-shadow': 0,

src/DataGrid.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ function DataGrid<R, SR, K extends Key>(
342342
const [selectedPosition, setSelectedPosition] = useState(
343343
(): SelectCellState | EditCellState<R> => ({ idx: -1, rowIdx: minRowIdx - 1, mode: 'SELECT' })
344344
);
345-
const [prevSelectedPosition, setPrevSelectedPosition] = useState(selectedPosition);
346345

347346
/**
348347
* refs
@@ -484,20 +483,14 @@ function DataGrid<R, SR, K extends Key>(
484483
*/
485484
useLayoutEffect(() => {
486485
if (
487-
!selectedCellIsWithinSelectionBounds ||
488-
isSamePosition(selectedPosition, prevSelectedPosition)
486+
focusSinkRef.current !== null &&
487+
selectedCellIsWithinSelectionBounds &&
488+
selectedPosition.idx === -1
489489
) {
490-
setPrevSelectedPosition(selectedPosition);
491-
return;
492-
}
493-
494-
setPrevSelectedPosition(selectedPosition);
495-
496-
if (focusSinkRef.current !== null && selectedPosition.idx === -1) {
497490
focusSinkRef.current.focus({ preventScroll: true });
498491
scrollIntoView(focusSinkRef.current);
499492
}
500-
}, [selectedCellIsWithinSelectionBounds, selectedPosition, prevSelectedPosition]);
493+
}, [selectedCellIsWithinSelectionBounds, selectedPosition]);
501494

502495
useLayoutEffect(() => {
503496
if (shouldFocusCell) {

0 commit comments

Comments
 (0)