From ffba007d6fbda637f374d678b550de03879d593f Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 29 Oct 2024 07:34:10 +0400 Subject: [PATCH] Block Editor: Fix React Complier error for 'useEventListeners' (#66495) Co-authored-by: Mamaduka Co-authored-by: tyxla --- .../src/components/rich-text/event-listeners/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/event-listeners/index.js b/packages/block-editor/src/components/rich-text/event-listeners/index.js index 46e721dfe5cf7..4ec67d8f30af9 100644 --- a/packages/block-editor/src/components/rich-text/event-listeners/index.js +++ b/packages/block-editor/src/components/rich-text/event-listeners/index.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { useMemo, useRef } from '@wordpress/element'; +import { useMemo, useRef, useInsertionEffect } from '@wordpress/element'; import { useRefEffect } from '@wordpress/compose'; /** @@ -35,7 +35,9 @@ const allEventListeners = [ export function useEventListeners( props ) { const propsRef = useRef( props ); - propsRef.current = props; + useInsertionEffect( () => { + propsRef.current = props; + } ); const refEffects = useMemo( () => allEventListeners.map( ( refEffect ) => refEffect( propsRef ) ), [ propsRef ]