Function use_hash

Source
pub fn use_hash<'hook>() -> impl 'hook + Hook<Output = UseHashHandle>
Expand description

A sensor hook that tracks brower’s location hash value.

§Example

use yew_hooks::prelude::*;

#[function_component(UseHash)]
fn hash() -> Html {
    let hash = use_hash();

    let onclick = {
        let hash = hash.clone();
        Callback::from(move |_| {
            hash.set("#/path/to/page?userId=123".to_string())
        })
    };
   
    html! {
        <>
            <button {onclick}>{ "Set hash to #/path/to/page?userId=123" }</button>
            <p>
                <b>{ " Current hash: " }</b>
                { &*hash }
            </p>
        </>
    }
}

§Note

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

pub fn use_hash() -> UseHashHandle {
    /* implementation omitted */
}