pub fn use_scroll<'hook>(
node: NodeRef,
) -> impl 'hook + Hook<Output = (i32, i32)>
Expand description
A sensor hook that tracks an HTML element’s scroll position.
§Example
use yew_hooks::prelude::*;
#[function_component(UseScroll)]
fn scroll() -> Html {
let node = use_node_ref();
let state = use_scroll(node.clone());
html! {
<div ref={node}>
<b>{ " X: " }</b>
{ state.0 }
<b>{ " Y: " }</b>
{ state.1 }
</div>
}
}
§Note
When used in function components and hooks, this hook is equivalent to:
pub fn use_scroll(node: NodeRef) -> (i32, i32) {
/* implementation omitted */
}