xylabs/sdk-react

View on GitHub
packages/shared/src/hooks/useMounted.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import { useEffect, useState } from 'react'

export const useMounted = () => {
  const [mounted, setMounted] = useState(true)
  useEffect(() => {
    // eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
    setMounted(true)
    return () => {
      setMounted(false)
    }
  }, [])
  return () => {
    return mounted
  }
}