Skip to content

Commit

Permalink
Don't use the callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 26, 2024
1 parent b86375d commit 7c92c8e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions packages/dataviews/src/dataviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ export default function DataViews< Item extends AnyItem >( {
onSelectionChange = defaultOnSelectionChange,
}: DataViewsProps< Item > ) {
const [ selectionState, setSelectionState ] = useState< string[] >( [] );
const selection =
selectionProperty === undefined ? selectionState : selectionProperty;
const setSelection =
setSelectionProperty === undefined
? setSelectionState
: setSelectionProperty;
const isUncontrolled =
selectionProperty === undefined || setSelectionProperty === undefined;
const selection = isUncontrolled ? selectionState : selectionProperty;
const setSelection = isUncontrolled
? setSelectionState
: setSelectionProperty;
const [ openedFilter, setOpenedFilter ] = useState< string | null >( null );

function setSelectionWithChange( value: SelectionOrUpdater ) {
Expand Down
8 changes: 4 additions & 4 deletions packages/dataviews/src/single-selection-checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export default function SingleSelectionCheckbox< Item extends AnyItem >( {
return;
}

onSelectionChange( ( state ) =>
state.includes( id )
? state.filter( ( itemId ) => id !== itemId )
: [ ...state, id ]
onSelectionChange(
selection.includes( id )
? selection.filter( ( itemId ) => id !== itemId )
: [ ...selection, id ]
);
} }
/>
Expand Down
8 changes: 4 additions & 4 deletions packages/dataviews/src/view-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ function GridItem< Item extends AnyItem >( {
if ( ! hasBulkAction ) {
return;
}
onSelectionChange( ( state ) =>
state.includes( id )
? state.filter( ( itemId ) => id !== itemId )
: [ ...state, id ]
onSelectionChange(
selection.includes( id )
? selection.filter( ( itemId ) => id !== itemId )
: [ ...selection, id ]
);
}
} }
Expand Down
8 changes: 4 additions & 4 deletions packages/dataviews/src/view-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ function TableRow< Item extends AnyItem >( {
! isTouchDevice.current &&
document.getSelection()?.type !== 'Range'
) {
onSelectionChange( ( state ) =>
state.includes( id )
? state.filter( ( itemId ) => id !== itemId )
: [ ...state, id ]
onSelectionChange(
selection.includes( id )
? selection.filter( ( itemId ) => id !== itemId )
: [ ...selection, id ]
);
}
} }
Expand Down

0 comments on commit 7c92c8e

Please sign in to comment.