Giter Site home page Giter Site logo

react-use-infinite-scroll-hook's Introduction

Create Release Workflow Release

React useInfiniteScroll-Hook

React Hook to call an action if an intersected element was reached

Prerequisites

Install

pnpm install react-use-infinite-scroll-hook

# Or the latest tarball from this repository
pnpm install https://github.com/tscharke/react-use-infinite-scroll-hook/releases/download/v1.0.1/react-use-infinite-scroll-hook-1.0.1.tar.gz

Usage

import { useInfiniteScroll } from 'react-use-infinite-scroll-hook';

const fetchMoreData = async () => {
	const response = await fetch('https://dummyjson.com/products')

	return await response.json()
}

export const MyComponent = ({ data }) => {
	const scrollElementRef = useInfiniteScroll<HTMLSpanElement>(fetchMoreData)

	return (
		<section>
			{data.map(({ id, title }) => <div key={id}>${title}</div>)}
			<span ref={scrollElementRef} style={{ visibility: 'hidden', width: 0, height: 0 }} />
		</section>
	)
}

๐Ÿ’ป Setup (on your machine)

# Check out the main-branch of this repository and switch into this directory
git clone [email protected]:tscharke/react-use-infinite-scroll-hook.git && cd "$(basename "$_" .git)"

# Install all dependencies
pnpm install

# Build module
pnpm run build

# Optional
# Run tests
pnpm run test

# Run linter
pnpm run lint

โค๏ธ๐Ÿ™ Love & Thanks

Many thanks to Denise Schaefer for here useIntersection-Hook, on which this React Hook based.

react-use-infinite-scroll-hook's People

Contributors

github-actions[bot] avatar

Watchers

Thomas Scharke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.