mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-23 17:09:21 -05:00
27 lines
569 B
Rust
27 lines
569 B
Rust
|
use leptos::*;
|
||
|
|
||
|
/// SSR compatibe `is_supported`
|
||
|
///
|
||
|
/// ## Usage
|
||
|
///
|
||
|
/// ```
|
||
|
/// # use leptos::*;
|
||
|
/// # use leptos_use::use_supported;
|
||
|
/// # use wasm_bindgen::JsValue;
|
||
|
/// #
|
||
|
/// # pub fn Demo(cx: Scope) -> impl IntoView {
|
||
|
/// let is_supported = use_supported(
|
||
|
/// cx,
|
||
|
/// || JsValue::from("getBattery").js_in(&window().navigator())
|
||
|
/// );
|
||
|
///
|
||
|
/// if is_supported() {
|
||
|
/// // do something
|
||
|
/// }
|
||
|
/// # view! { cx, }
|
||
|
/// # }
|
||
|
/// ```
|
||
|
pub fn use_supported(cx: Scope, callback: impl Fn() -> bool + 'static) -> Signal<bool> {
|
||
|
Signal::derive(cx, callback)
|
||
|
}
|