Skip to content

Commit

Permalink
DataViews: memoize onSetSelection (#57458)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Dec 29, 2023
1 parent 0d2bf01 commit 9431114
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/dataviews/src/dataviews.js
Expand Up @@ -5,7 +5,7 @@ import {
__experimentalVStack as VStack,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { useMemo, useState } from '@wordpress/element';
import { useMemo, useState, useCallback } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -35,10 +35,13 @@ export default function DataViews( {
} ) {
const [ selection, setSelection ] = useState( [] );

const onSetSelection = ( items ) => {
setSelection( items.map( ( item ) => item.id ) );
onSelectionChange( items );
};
const onSetSelection = useCallback(
( items ) => {
setSelection( items.map( ( item ) => item.id ) );
onSelectionChange( items );
},
[ setSelection, onSelectionChange ]
);

const ViewComponent = VIEW_LAYOUTS.find(
( v ) => v.type === view.type
Expand Down

0 comments on commit 9431114

Please sign in to comment.