Function use_location

Source
pub fn use_location<'hook>() -> impl 'hook + Hook<Output = UseStateHandle<LocationState>>
Expand description

A sensor hook that tracks brower’s location value.

§Example

use yew_hooks::prelude::*;

#[function_component(UseLocation)]
fn location() -> Html {
    let location = use_location();
   
    html! {
        <>
            <p>
                <b>{ "trigger: " }</b>
                { &location.trigger }
            </p>
            <p>
                <b>{ "state: " }</b>
                { format!("{:?}", &location.state) }
            </p>
            <p>
                <b>{ "length: " }</b>
                { &location.length }
            </p>
            <p>
                <b>{ "hash: " }</b>
                { &location.hash }
            </p>
            <p>
                <b>{ "host: " }</b>
                { &location.host }
            </p>
            <p>
                <b>{ "hostname: " }</b>
                { &location.hostname }
            </p>
            <p>
                <b>{ "href: " }</b>
                { &location.href }
            </p>
            <p>
                <b>{ "origin: " }</b>
                { &location.origin }
            </p>
            <p>
                <b>{ "pathname: " }</b>
                { &location.pathname }
            </p>
            <p>
                <b>{ "port: " }</b>
                { &location.port }
            </p>
            <p>
                <b>{ "protocol: " }</b>
                { &location.protocol }
            </p>
            <p>
                <b>{ "search: " }</b>
                { &location.search }
            </p>
        </>
    }
}

§Note

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

pub fn use_location() -> UseStateHandle<LocationState> {
    /* implementation omitted */
}