Skip to content

Commit

Permalink
Node can be null
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed May 21, 2021
1 parent b700c0e commit eaab6c1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ _Parameters_

_Returns_

- `import('react').RefCallback<Node>`: Ref callback.
- `import('react').RefCallback<Node | null>`: Ref callback.

<a name="useResizeObserver" href="#useResizeObserver">#</a> **useResizeObserver**

Expand Down
4 changes: 2 additions & 2 deletions packages/compose/src/hooks/use-ref-effect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import { useCallback, useRef } from '@wordpress/element';
* @param {(node: Node) => (() => void) | undefined} callback Callback with ref as argument.
* @param {import('react').DependencyList} dependencies Dependencies of the callback.
*
* @return {import('react').RefCallback<Node>} Ref callback.
* @return {import('react').RefCallback<Node | null>} Ref callback.
*/
export default function useRefEffect( callback, dependencies ) {
/** @type {import('react').MutableRefObject<(() => void) | undefined>} */
const cleanup = useRef();
return useCallback( ( /** @type {Node} */ node ) => {
return useCallback( ( /** @type {Node | null} */ node ) => {
if ( node ) {
cleanup.current = callback( node );
} else if ( cleanup.current ) {
Expand Down

0 comments on commit eaab6c1

Please sign in to comment.