Skip to content

Commit

Permalink
Rich Text: Fix React Complier error for 'useEventListeners' (WordPres…
Browse files Browse the repository at this point in the history
…s#66460)

* 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 and karthick-murugan committed Nov 13, 2024
1 parent d61856c commit 06f9dd6
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 06f9dd6

Please sign in to comment.