Function use_window_size

Source
pub fn use_window_size<'hook>() -> impl 'hook + Hook<Output = (f64, f64)>
Expand description

A sensor hook that tracks dimensions of the browser window.

§Example

use yew_hooks::prelude::*;

#[function_component(UseWindowSize)]
fn window_size() -> Html {
    let state = use_window_size();
    
    html! {
        <>
            <b>{ " Width: " }</b>
            { state.0 }
            <b>{ " Height: " }</b>
            { state.1 }
        </>
    }
}

§Note

When used in function components and hooks, this hook is equivalent to:

pub fn use_window_size() -> (f64, f64) {
    /* implementation omitted */
}