leptos_use/
use_supported.rs

1use leptos::prelude::*;
2
3/// SSR compatibe `is_supported`
4///
5/// ## Usage
6///
7/// ```
8/// # use leptos::prelude::*;
9/// # use leptos_use::{use_supported, js};
10/// # use wasm_bindgen::JsValue;
11/// #
12/// # pub fn Demo() -> impl IntoView {
13/// let is_supported = use_supported(
14///     || js!("getBattery" in &window().navigator())
15/// );
16///
17/// if is_supported.get() {
18///     // do something
19/// }
20/// #    view! { }
21/// # }
22/// ```
23pub fn use_supported(callback: impl Fn() -> bool + Send + Sync + 'static) -> Signal<bool> {
24    #[cfg(feature = "ssr")]
25    {
26        let _ = callback;
27        Signal::derive(|| false)
28    }
29
30    #[cfg(not(feature = "ssr"))]
31    {
32        Signal::derive(callback)
33    }
34}