Skip to content

Commit

Permalink
Fix useLatestRef Hook
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Apr 11, 2024
1 parent dc34e32 commit 3df5a59
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/mui-base/src/utils/useLatestRef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';
import * as React from 'react';
import { useEnhancedEffect } from './useEnhancedEffect';

/**
* @ignore - internal hook.
*/
export function useLatestRef<T>(value: T) {
const ref = React.useRef(value);
useEnhancedEffect(() => {
ref.current = value;
});
return ref;
}

0 comments on commit 3df5a59

Please sign in to comment.