Leptos-Use Guide

use_idle

Tracks whether the user is being inactive.

Demo

Usage

use leptos::prelude::*;
use leptos::logging::log;
use leptos_use::{use_idle, UseIdleReturn};

#[component]
fn Demo() -> impl IntoView {
let UseIdleReturn {
    idle, last_active, ..
} = use_idle(5 * 60 * 1000); // 5 minutes

log!("{}", idle.get()); // true or false

view! { }
}

Programatically resetting:

use std::time::Duration;
use leptos::prelude::*;
use leptos::logging::log;
use leptos_use::{use_idle, UseIdleReturn};

#[component]
fn Demo() -> impl IntoView {
let UseIdleReturn {
    idle, last_active, reset
} = use_idle(5 * 60 * 1000); // 5 minutes

reset(); // restarts the idle timer. Does not change the `last_active` value.

view! { }
}

SendWrapped Return

The returned closure reset is a sendwrapped function. It can only be called from the same thread that called use_idle.

Server-Side Rendering

On the server this will always return static signals

UseIdleReturn{
    idle: Signal(initial_state),
    last_active: Signal(now),
    reset: || {}
}

Feature

This function is only available if the crate feature use_idle is enabled

Types

Source

SourceDemoDocs