Skip to content

Commit

Permalink
feat: Update hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
nuintun committed Jun 1, 2024
1 parent 26f3d6b commit 4b4abe9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/js/hooks/useLatestRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module useLatestRef
*/

import React, { useRef } from 'react';
import React, { useMemo, useRef } from 'react';

/**
* @function useLatestRef
Expand All @@ -18,7 +18,8 @@ export default function useLatestRef<T>(value: T): React.MutableRefObject<T>;
export default function useLatestRef<T = undefined>(value?: T): React.MutableRefObject<T | undefined> {
const valueRef = useRef(value);

valueRef.current = value;
// https://github.com/alibaba/hooks/issues/728
valueRef.current = useMemo(() => value, [value]);

return valueRef;
}

0 comments on commit 4b4abe9

Please sign in to comment.