@idevelopment-hu/react-infinite-list
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@idevelopment-hu/react-infinite-list

Simple React infinite list component implemented with IntersectionObserver API

Install

  npm install --save @idevelopment-hu/react-infinite-list
  
  or

  yarn add @idevelopment-hu/react-infinite-list

Using

// create DTO for the data
export type PostDTO = {
  id: number;
  userId: number;
  title: string;
  body: string;
};

// implement InfiniteListDataSource<T>
import { InfiniteListDataSource } from "@idevelopment-hu/react-infinite-list";

export default class DataSource implements InfiniteListDataSource<PostDTO> {
  data: PostDTO[] = [];
  hasNextPage: boolean = true;

  loadNextPage = async () => {
    // load next data then update this.data
  };
}

// use the InfiniteList component
import { InfiniteList } from "@idevelopment-hu/react-infinite-list";

<InfiniteList dataSource={dataSource}>
    {(post: PostDTO, index) => (
    <div key={index}>
        <span>{post.id}</span>
        <span>{post.title}</span>
    </div>
    )}
</InfiniteList>

See example for more details

Package Sidebar

Install

npm i @idevelopment-hu/react-infinite-list

Weekly Downloads

157

Version

1.0.1

License

MIT

Unpacked Size

36.3 kB

Total Files

7

Last publish

Collaborators

  • csfoldesi