Memoize block context

This commit is contained in:
Matt Sherman 2023-10-13 00:19:11 -04:00
parent 86a0a15588
commit 09b0cdcef7
1 changed files with 8 additions and 1 deletions

View File

@ -54,6 +54,13 @@ export function BlockEditor( {
}: BlockEditorProps ) {
useConfirmUnsavedProductChanges( productType );
const blockContext = useMemo( () => {
return {
...context,
productType,
};
}, [ context, productType ] );
const canUserCreateMedia = useSelect( ( select: typeof WPSelect ) => {
const { canUser } = select( 'core' );
return canUser( 'create', 'media', '' ) !== false;
@ -106,7 +113,7 @@ export function BlockEditor( {
return (
<div className="woocommerce-product-block-editor">
<BlockContextProvider value={ { ...context, productType } }>
<BlockContextProvider value={ blockContext }>
<BlockEditorProvider
value={ blocks }
onInput={ onInput }