ant-design/components/_util/hooks/useMounted.ts

15 lines
252 B
TypeScript
Raw Normal View History

2021-12-28 17:21:00 +08:00
import * as React from 'react';
export default function useMounted() {
2021-12-28 17:21:00 +08:00
const mountedRef = React.useRef<boolean>(true);
React.useEffect(
() => () => {
2021-12-28 17:21:00 +08:00
mountedRef.current = false;
},
[],
);
2021-12-28 17:21:00 +08:00
return () => mountedRef.current;
2021-12-28 17:21:00 +08:00
}