Skip to content

Commit

Permalink
remove local useUpdateEffect in favor of the utils version
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed Oct 19, 2022
1 parent 4a3aa8c commit 8af7a03
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
27 changes: 4 additions & 23 deletions packages/components/src/ui/context/context-system-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,20 @@ import {
createContext,
useContext,
useRef,
useEffect,
useMemo,
memo,
} from '@wordpress/element';
import warn from '@wordpress/warning';
/**
* Internal dependencies
*/
import { useUpdateEffect } from '../../utils';

export const ComponentsContext = createContext(
/** @type {Record<string, any>} */ ( {} )
);
export const useComponentsContext = () => useContext( ComponentsContext );

/**
* Runs an effect only on update (i.e., ignores the first render)
*
* @param {import('react').EffectCallback} effect
* @param {import('react').DependencyList} deps
*/
function useUpdateEffect( effect, deps ) {
const mounted = useRef( false );
useEffect( () => {
if ( mounted.current ) {
return effect();
}
mounted.current = true;
return undefined;
// Disable reasons:
// 1. This hook needs to pass a dep list that isn't an array literal
// 2. `effect` is missing from the array, and will need to be added carefully to avoid additional warnings
// see https://github.com/WordPress/gutenberg/pull/41166
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps );
}

/**
* Consolidates incoming ContextSystem values with a (potential) parent ContextSystem value.
*
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/utils/hooks/use-update-effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { useRef, useEffect } from '@wordpress/element';
*/
function useUpdateEffect( effect, deps ) {
const mounted = useRef( false );

useEffect( () => {
if ( mounted.current ) {
return effect();
Expand Down

0 comments on commit 8af7a03

Please sign in to comment.