Breaking Change
In order to support having multiple instances of <InfiniteLoader /> on a page at once, the component has been changed to require the user to instantiate the LoaderState class themselves and pass an instance in via props. See the Example or Getting Started section of the README for a concrete example.
Migrating
Migration consists of the following three steps
- Modify your import to point at the uppercase
LoaderStateclass - Instantiate an instance of
LoaderStateyourself - Pass that instance into the
InfiniteLoadercomponent as a prop
<script lang="ts">
+ import { InfiniteLoader, LoaderState } from "svelte-infinite"
- import { InfiniteLoader, loaderState } from "svelte-infinite"
+ const loaderState = new LoaderState()
const allItems = $state([])
const loadMore = async () => {
const res = fetch("...")
const data = await res.json()
allItems.push(...data)
loaderState.loaded()
}
</script>
+ <InfiniteLoader {loaderState} triggerLoad={loadMore}>
- <InfiniteLoader triggerLoad={loadMore}>
{#each allItems as user (user.id)}
<div>{user.name}</div>
{/each}
</InfiniteLoader>