![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
react-easy-infinite-scroll-hook
Advanced tools
This hook allows you to create simple, lightweight components with infinite scrolling in all directions, supporting both windowed and scrollable elements.
A hook that will save you from endless scrolling problems! Infinite scrolling that really works and is very easy to integrate! This hook allows you to create simple, lightweight components with infinite scrolling in all directions, supporting both windowed and scrollable elements.
up
, down
, left
, right
)100%
test coverage~1.9kB
# with npm
npm install --save react-easy-infinite-scroll-hook
# with yarn
yarn add react-easy-infinite-scroll-hook
import { useInfiniteScroll } from 'react-easy-infinite-scroll-hook';
const InfiniteListComponent = ({ isLoading, items, canLoadMore, next }) => {
const { setRef } = useInfiniteScroll({
next,
rowLength: items.length,
hasMore: { down: canLoadMore },
});
return (
<div
ref={setRef}
style={{
height: 500,
overflowY: 'auto',
}}
>
{items.map((item) => (
<div key={item.key}>{item.value}</div>
))}
{isLoading && <div>Loading...</div>}
</div>
);
};
List | |
---|---|
Grid |
import { useInfiniteScroll } from 'react-easy-infinite-scroll-hook';
import { List } from 'react-virtualized';
const VirtualizedInfiniteListComponent = ({ isLoading, items, canLoadMore, next }) => {
const { setRef } = useInfiniteScroll({
next,
rowLength: items.length,
hasMore: { down: canLoadMore },
});
return (
<List
ref={setRef}
width={500}
height={500}
rowHeight={60}
rowCount={items.length}
rowRenderer={({ key, index, style }) => {
const item = data[index];
return (
<div key={key} style={style}>
{item}
</div>
);
}}
/>
);
};
After initialization, this hook returns a setRef
function, which you must pass to your element ref
.
Name | Required | Description | Type | Default Value |
---|---|---|---|---|
next | Yes | A callback when more items are requested by the user. Receives a single parameter specifying the direction to load e.g. (direction): Promise<void> | Function | |
hasMore | Yes | Whether there are more items to be loaded. Expect object with directions to load { up: false, down: false, left: false, right: false } | object | |
rowLength | Condition | Number of items in a vertical list (scroll axis Y ). Required if you are using vertical scroll. | number | |
columnLength | Condition | Number of items in a horizontal list (scroll axis X ). Required if you are using horizontal scroll. | number | |
onScroll | The callback is called when the container is scrolled: ({ clientHeight: number, scrollHeight: number, scrollTop: number, clientWidth: number, scrollWidth: number, scrollLeft: number }): void | Function | ||
initialScroll | The initial scroll position of the element, which is applied after the ref has been initialized | object | ||
reverse | The direction of the scroll axis is used to create scrolling in the opposite direction, for example when using the CSS style flex-direction: 'row-reverse' | object | ||
scrollThreshold | The threshold at which the next function is called. It can be specified in pixels from the scrollbar value, for example '200px' and as a percentage of the element value 0.6 = 60% | number or string | 1 |
flex-direction: 'row-reverse'
?Yes, just pass reverse: { vertical: true }
to the props.
react-virtualized
MultiGrid
component?MultiGrid
is a complex component with a lot of scrollable containers, and to use it you must specify the correct container for the useRef
function:
import React, { useCallback } from 'react';
import { useInfiniteScroll } from 'react-easy-infinite-scroll-hook';
import { MultiGrid } from 'react-virtualized';
const VirtualizedInfiniteListComponent = ({ isLoading, items, canLoadMore, next }) => {
const { setRef } = useInfiniteScroll({
next,
columnLength: items.length,
hasMore: { right: canLoadMore },
});
// Use `useCallback` so we don't recreate the function on each render - Could result in infinite loop
const selectRef = useCallback(
(node) => {
setRef(node._bottomRightGrid)
},
[setRef],
);
return (
<MultiGrid
ref={selectRef}
{ ...rest}
/>
);
};
MIT © vdmrgv
FAQs
A react hook for creating simple, fast and lightweight components with infinite scrolling in any direction, supporting both windowed and scrollable elements.
The npm package react-easy-infinite-scroll-hook receives a total of 1,084 weekly downloads. As such, react-easy-infinite-scroll-hook popularity was classified as popular.
We found that react-easy-infinite-scroll-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.