Skip to content

Commit

Permalink
Memoize selected render value
Browse files Browse the repository at this point in the history
  • Loading branch information
brookewp committed Jan 23, 2024
1 parent d14ab4b commit e3c0be1
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -61,8 +61,10 @@ export function _CustomSelect( {
> ) {
const { value: currentValue } = store.useState();

const computedRenderSelectedValue =
renderSelectedValue ?? defaultRenderSelectedValue;
const computedRenderSelectedValue = useMemo(
() => renderSelectedValue ?? defaultRenderSelectedValue,
[ renderSelectedValue ]
);

return (
<>
Expand Down

0 comments on commit e3c0be1

Please sign in to comment.