pub fn use_infinite_scroll<'hook, Callback>(
node: NodeRef,
callback: Callback,
) -> impl 'hook + Hook<Output = ()>where
Callback: Fn() + 'static + 'hook,
Expand description
A sensor hook that tracks infinite scrolling of the element.
§Example
use yew_hooks::prelude::*;
#[function_component(UseInfiniteScroll)]
fn infinite_scroll() -> Html {
let node = use_node_ref();
let state = use_list(vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
{
let state = state.clone();
use_infinite_scroll(node.clone(), move || {
let max = state.current().len() + 1;
let mut more = vec![max, max + 1, max + 2, max + 3, max + 4];
state.append(&mut more);
});
}
html! {
<div ref={node}>
{
for state.current().iter().map(|element| {
html! { <p>{ element }</p> }
})
}
</div>
}
}
§Note
When used in function components and hooks, this hook is equivalent to:
pub fn use_infinite_scroll<Callback>(node: NodeRef, callback: Callback)
where
Callback: Fn() + 'static,
{
/* implementation omitted */
}