
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-infinite-scroll-optimistic
Advanced tools
A React library for implementing infinite scrolling with optimistic updates
A lightweight and customizable React library for implementing infinite scrolling with built-in support for optimistic updates.
npm install react-infinite-scroll-optimistic
# or
yarn add react-infinite-scroll-optimistic
import { useInfiniteScroll, InfiniteScroll } from 'react-infinite-scroll-optimistic';
function MyList() {
const scrollResult = useInfiniteScroll({
fetchItems: async (page) => {
const response = await fetch(`/api/items?page=${page}`);
return response.json();
},
});
return (
<InfiniteScroll
scrollResult={scrollResult}
renderItem={(item, index, ref) => (
<div key={item.id} ref={ref}>
{item.name}
</div>
)}
/>
);
}
import { useInfiniteScroll, useOptimisticActions, InfiniteScroll } from 'react-infinite-scroll-optimistic';
function MyList() {
const scrollResult = useInfiniteScroll({
fetchItems: async (page) => {
const response = await fetch(`/api/items?page=${page}`);
return response.json();
},
});
const [optimisticItems, addOptimisticAction] = useOptimisticActions(
scrollResult.items,
(state, action) => {
switch (action.type) {
case 'ADD_ITEM':
return [...state, action.item];
case 'REMOVE_ITEM':
return state.filter(item => item.id !== action.id);
default:
return state;
}
}
);
const handleAddItem = async () => {
// Show optimistic update immediately
const optimisticItem = { id: 'temp-' + Date.now(), name: 'New Item', status: 'pending' };
addOptimisticAction({ type: 'ADD_ITEM', item: optimisticItem });
// Make API call
try {
const response = await fetch('/api/items', {
method: 'POST',
body: JSON.stringify({ name: 'New Item' }),
});
const newItem = await response.json();
// Update actual state with server response
scrollResult.setItems([...scrollResult.items, newItem]);
} catch (error) {
console.error('Failed to add item:', error);
// Handle error, maybe revert the optimistic update
}
};
return (
<>
<button onClick={handleAddItem}>Add Item</button>
<InfiniteScroll
scrollResult={scrollResult}
renderItem={(item, index, ref) => (
<div key={item.id} ref={ref}>
{item.name} {item.status === 'pending' && '(Saving...)'}
</div>
)}
/>
</>
);
}
useInfiniteScrollfunction useInfiniteScroll<T>({
fetchItems,
initialPage,
threshold,
loadImmediately,
initialItems,
}: {
fetchItems: (page: number) => Promise<T[]>;
initialPage?: number;
threshold?: number;
loadImmediately?: boolean;
initialItems?: T[];
}): {
items: T[];
loading: boolean;
error: Error | null;
hasMore: boolean;
loadMore: () => Promise<void>;
lastItemRef: (node: Element | null) => void;
reset: () => void;
setItems: React.Dispatch<React.SetStateAction<T[]>>;
page: number;
};
useOptimisticActionsfunction useOptimisticActions<T, A>(
initialState: T[],
updateFn: (currentState: T[], action: A) => T[]
): [T[], (action: A) => void];
InfiniteScroll<InfiniteScroll
scrollResult={/* result from useInfiniteScroll */}
renderItem={(item, index, lastItemRef) => (
/* render your item */
)}
loadingComponent={/* optional custom loading component */}
errorComponent={/* optional custom error component */}
endComponent={/* optional custom end of list component */}
emptyComponent={/* optional custom empty list component */}
className={/* optional class name */}
style={/* optional inline styles */}
>
{/* optional header content */}
</InfiniteScroll>
MIT
FAQs
A React library for implementing infinite scrolling with optimistic updates
The npm package react-infinite-scroll-optimistic receives a total of 0 weekly downloads. As such, react-infinite-scroll-optimistic popularity was classified as not popular.
We found that react-infinite-scroll-optimistic demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.