Socket
Book a DemoInstallSign in
Socket

use-apollo-infinite-scroll

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-apollo-infinite-scroll

infinite pagination react package hook for react using apollo client.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

use-apollo-infinite-scroll

This package provides a custom hook useApolloInfiniteScroll to implement infinite scroll pagination using Apollo Client.

Installation

You can install the package via npm or yarn:

npm install use-apollo-infinite-scroll
yarn add use-apollo-infinite-scroll

Usage

Here is an example of how to use the hook in component:

import { gql } from '@apollo/client'
import React, { useState } from 'react'
import useApolloInfiniteScroll from 'use-apollo-infinite-scroll'

const ITEMS_QUERY = gql`
  query itemsQuery($cursor: String, $limit: Int) {
    items(cursor: $cursor, limit: $limit) {
      id
      name
    }
  }
`

const App = () => {
	const { data, lastItemRef, loading } = useApolloInfiniteScroll(ITEMS_QUERY, {
		limit: 10,
		dataKey: 'items',
		idKey: 'id',
		populate: 'user',
	})
	
	return (
		<div>
			<h1>Items</h1>
			<ul>
				{data?.map((item, index) => (
					<li key={item.id} ref={data.length - 1 === index ? lastItemRef : null}>
						{item.name}
					</li>
				))}
			</ul>
			{loading && <p>Loading...</p>}
		</div>
	)
}

export default App

Props

  • idKey - The key used to identify each item (default: 'id').
  • dataKey - The key in the response data where the list of items is located.
  • suspense - A boolean to determine if suspense mode is used.
  • variables - Additional variables to pass to the query.
  • limit - Number of items to fetch per request (default: 30).
  • sortOrder - Order to sort the items ('asc' or 'desc').
  • filters - Filter object to filter the items.

License

This project is licensed under the MIT License.

Development

To start the development server, run:

yarn dev

Keywords

react

FAQs

Package last updated on 11 Jun 2024

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.