Skip to content

Commit

Permalink
Rich Text: Fix React Complier error for 'useEventListeners' (#66460)
Browse files Browse the repository at this point in the history
* Rich Text: Fix React Complier error for 'useEventListeners'
* Try 'useInsertionEffect' hook

Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent e7f2d01 commit 029716e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/rich-text/src/component/event-listeners/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useMemo, useRef } from '@wordpress/element';
import { useMemo, useRef, useInsertionEffect } from '@wordpress/element';
import { useRefEffect } from '@wordpress/compose';

/**
Expand All @@ -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 ]
Expand Down

0 comments on commit 029716e

Please sign in to comment.