From e3c0be1af2e83df75b23ae5af98f8bcb0891657c Mon Sep 17 00:00:00 2001 From: brookewp Date: Mon, 22 Jan 2024 16:39:11 -0800 Subject: [PATCH] Memoize selected render value --- .../src/custom-select-control-v2/custom-select.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/components/src/custom-select-control-v2/custom-select.tsx b/packages/components/src/custom-select-control-v2/custom-select.tsx index a31fb09be77450..6ed545ce871a9d 100644 --- a/packages/components/src/custom-select-control-v2/custom-select.tsx +++ b/packages/components/src/custom-select-control-v2/custom-select.tsx @@ -6,7 +6,7 @@ import * as Ariakit from '@ariakit/react'; /** * WordPress dependencies */ -import { createContext } from '@wordpress/element'; +import { createContext, useMemo } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; /** @@ -61,8 +61,10 @@ export function _CustomSelect( { > ) { const { value: currentValue } = store.useState(); - const computedRenderSelectedValue = - renderSelectedValue ?? defaultRenderSelectedValue; + const computedRenderSelectedValue = useMemo( + () => renderSelectedValue ?? defaultRenderSelectedValue, + [ renderSelectedValue ] + ); return ( <>