react-native-use-idle

useIdle returns a boolean if idle

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
react-native-use-idle
001.14.04 months ago4 months agoMinified + gzip package size for react-native-use-idle in KB

Readme

A simple way to detect inactivity.
// you need to add IdleProvider at the top level
const isIdle = useIdle()

Getting Started

Install

yarn add react-native-use-idle

Add the Provider At the Top Level

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)
        <IdleProvider>
            {...your app}
         </IdleProvider>
    )
}

Using useIdle

import { useIdle } from "react-native-use-idle";

const Component = () => {
    const isIdle = useIdle();
    useEffect(() => {
         if (!isIdle) console.log("not idle");
         console.log("is idle");
    },[])
}