mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
Make useMountedState return a single function instead of a new one each time;
This commit is contained in:
parent
987e08af61
commit
12608fe5be
@ -1,7 +1,8 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useEffect, useRef, useCallback } from 'react';
|
||||
|
||||
export default function useMountedState(): () => boolean {
|
||||
const mountedRef = useRef<boolean>(false);
|
||||
const get = useCallback(() => mountedRef.current, []);
|
||||
|
||||
useEffect(() => {
|
||||
mountedRef.current = true;
|
||||
@ -11,5 +12,5 @@ export default function useMountedState(): () => boolean {
|
||||
};
|
||||
});
|
||||
|
||||
return () => mountedRef.current;
|
||||
return get;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user