Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

solid-infinite-scroll-fork

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solid-infinite-scroll-fork

infinite scroll library for solid-js

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

solid-infinite-scroll

Infinite scrolling / Dynamic list loading library for SolidJS

Installation

First, install the library from the npm registry:

yarn add -D solid-infinite-scroll

Second, import it in the tsx component you're working on:

import InfiniteScroll from 'solid-infinite-scroll';

Usage

To use the infinite scroll module, you would need a signal/resource for data storage, and implement two functions:

  • each should return the currently stored data array, this is similar to the SolidJS <For> component
  • hasMore should return true if more data is available
  • next should load more data into the array stored by each and return nothing

For example, if you want to load all data at once but only display e.g. 50 at a time, you can do:

const fetchApi = async () => await (await fetch("https://api.example.com/list").json() as string[]

export default function App() {
  const [api] = createResource(fetchApi)
  
  const [scrollIndex, setScrollIndex] = createSignal(50)
  const scrollNext = () => setScrollIndex(Math.min(scrollIndex() + 50, api().length))
  
  return (
    <InfiniteScroll each={api()?.slice(0, scrollIndex())} 
      hasMore={scrollIndex() < api()?.length}
      next={scrollNext}>
      {(item, index) =>
        <div>{item}</div>
      }
    </InfiniteScroll>
  )
}

Keywords

FAQs

Package last updated on 16 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc