Skip to content

v0.5.0

Latest
Compare
Choose a tag to compare
@ndom91 ndom91 released this 19 Mar 14:06
· 1 commit to main since this release
v0.5.0
c8ce22d

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

  1. Modify your import to point at the uppercase LoaderState class
  2. Instantiate an instance of LoaderState yourself
  3. Pass that instance into the InfiniteLoader component 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>