diff --git a/packages/rich-text/src/component/event-listeners/index.js b/packages/rich-text/src/component/event-listeners/index.js index a6327fe6637c37..4f69db36db06a0 100644 --- a/packages/rich-text/src/component/event-listeners/index.js +++ b/packages/rich-text/src/component/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'; /** @@ -25,7 +25,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 ]