use_timestamp
Reactive current timestamp.
Demo
Usage
use leptos::prelude::*;
use leptos_use_timestamp::use_timestamp;
#[component]
fn Demo() -> impl IntoView {
let timestamp = use_timestamp();
view! { }
}
With controls:
use leptos::prelude::*;
use leptos_use_timestamp::{use_timestamp_with_controls, UseTimestampReturn};
#[component]
fn Demo() -> impl IntoView {
let UseTimestampReturn {
timestamp,
is_active,
pause,
resume,
} = use_timestamp_with_controls();
view! { }
}
SendWrapped Return
The returned closures pause and resume of the ..._with_controls versions are
sendwrapped functions. They can only be called from the same thread that called
use_timestamp_with_controls.
Server-Side Rendering
Make sure you follow the instructions in Server-Side Rendering.
On the server this function will return a signal with the milliseconds since the Unix epoch.
But the signal will never update (as there’s no request_animation_frame on the server).
Installation
cargo add leptos-use-timestamp
Options
UseTimestampOptions
Options for use_timestamp_with_controls_and_options.
Every option is set with a builder method of the same name, e.g. UseTimestampOptions::default().offset(...). See also the API docs.
offset
Type: f64
Offset value in milliseconds that is added to the returned timestamp. Defaults to 0.0.
immediate
Type: bool
Whether to update the timestamp immediately. Defaults to true.
interval
Type: TimestampInterval
Update interval in milliseconds or RequestAnimationFrame. Defaults to RequestAnimationFrame.
callback
Type: Rc<dyn Fn(f64)>
Callback to be called whenever the timestamp is updated.