useRefMounted.ts 258 B

123456789101112
  1. import { useRef, useEffect } from 'react';
  2. export const useRefMounted = () => {
  3. const refMounted = useRef(false);
  4. useEffect(() => {
  5. refMounted.current = true;
  6. return () => {
  7. refMounted.current = false;
  8. };
  9. });
  10. return refMounted;
  11. };