From 20c9598b616de369674844dceab578c609d40387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:17:24 +0100 Subject: [PATCH] DataViews: memoize onSetSelection --- packages/dataviews/src/dataviews.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/dataviews/src/dataviews.js b/packages/dataviews/src/dataviews.js index 1b46557028636c..91ea942ee6d22a 100644 --- a/packages/dataviews/src/dataviews.js +++ b/packages/dataviews/src/dataviews.js @@ -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 @@ -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