useIdle returns a boolean if idle
npm install react-native-use-idleA simple way to detect inactivity.
``ts`
// you need to add IdleProvider at the top level
const isIdle = useIdle()
#### Add the Provider At the Top Level
`ts
import { IdleProvider } from "react-native-use-idle";// top level of code you want to monitor
const App = () => {
return (
// optionally set a timeForInactivity variable (default 30s)
{...your app}
)
}
`
#### Using useIdle
`ts
import { useIdle } from "react-native-use-idle";const Component = () => {
const isIdle = useIdle();
useEffect(() => {
if (!isIdle) console.log("not idle");
console.log("is idle");
},[])
}
``