Skip to content

Commit

Permalink
Update packages/components/src/utils/hooks/use-prop-ref.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Haz <hazdiego@gmail.com>
  • Loading branch information
sarayourfriend and diegohaz authored Jul 1, 2021
1 parent 3559eca commit 2e8b22d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/components/src/utils/hooks/use-prop-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ import { useEffect, useRef } from '@wordpress/element';
* @param prop
* @return The prop reference.
*/
export function usePropRef< T >( prop: T ): MutableRefObject< T > {
const propRef = useRef( prop );
export function useLatestRef< T >( value: T ): RefObject< T > {
const ref = useRef( value );

useEffect( () => {
propRef.current = prop;
}, [ prop ] );
useLayoutEffect( () => {
ref.current = prop;
} );

return propRef;
return ref;
}

0 comments on commit 2e8b22d

Please sign in to comment.