Infinite Scroll Component for Svelte.
npm i svelte-infinite-scrolling
An example of how to use the library:
<script>
import { onMount } from "svelte";
import InfiniteScroll from "./InfiniteScroll.svelte";
let posts = [];
async function getPosts() {
let res = await fetch("https://meme-api.herokuapp.com/gimme/10");
let data = await res.json();
posts = [...posts, ...data.memes];
console.log(posts);
}
onMount(() => {
getPosts();
});
</script>
{#each posts as item}
<h1 style="padding:1em">{item.title}</h1>
{/each}
<InfiniteScroll on:scroll={getPosts} />
Component props:
Prop | Type | Default | Description |
---|---|---|---|
on:scroll |
function | 0 | Function You Want To Run While Scrolling |