Synphonyte / leptos-use

Collection of essential Leptos utilities inspired by React-Use / VueUse
https://leptos-use.rs/
Apache License 2.0
328 stars 72 forks source link

`use_infinite_scroll` stops calling `on_load_more` after shrinking content #122

Open Reisz opened 4 months ago

Reisz commented 4 months ago

In the following example, the scroll area initially populates and updates as expected, but pressing reset while the scroll is at the top will cause the updates to stop.

let (count, set_count) = create_signal(1);
let reset = move |_| set_count(1);

let data: &_ = (0..1000).collect::<Vec<_>>().leak();
let elements = move || data.iter().copied().take(count()).collect::<Vec<_>>();

let scroll_area = create_node_ref();
let _ = use_infinite_scroll(scroll_area, move |_| {
    std::future::ready(set_count(count.get_untracked() + 1))
});

view! {
    <button on:click=reset>Reset</button>
    <div style="height: 20rem; overflow-y: auto" ref=scroll_area>
        <For each=elements key=|id| *id children=move |id| view! { <div>{id}</div> }/>
    </div>
}