
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
use-pull-to-refresh
Advanced tools
A simple React custom hook for pull-to-refresh function that support NextJs
A simple React custom hook for pull-to-refresh function that support NextJs SSR.
Lots of web application needs custom scroll area for various reasons, however since we are not using browser native scroll,
the native pull to refresh API is unusable since it's tied to the scroll event on html
tag. This hooks is the solution to
resolve this issue by recreating the native pull top behavior while also let you choose what proccess to run on each pull
event end.
This project requires NodeJS (version 16 or later) and React 17+
This custom hook helps you implement the pull-to-refresh feature in your app. It supports NextJs SSR that some other packages don't. It also allows support of a custom Scroll Area that was created by yourself.
'window' is not defined
when using with NextJs SSR.BEFORE YOU INSTALL: please read the prerequisites
To install and set up the library, run:
$ npm i use-pull-to-refresh
Or if you prefer using Yarn:
$ yarn add use-pull-to-refresh
Or if you prefer using pnpm:
$ pnpm add use-pull-to-refresh
import { useRouter } from 'next/router';
import { usePullToRefresh } from 'use-pull-to-refresh';
const MAXIMUM_PULL_LENGTH = 240;
const REFRESH_THRESHOLD = 180;
export default function PageRefresh() {
const { isReady, reload } = useRouter();
const { isRefreshing, pullPosition } = usePullToRefresh({
// you can choose what behavior for `onRefresh`, could be calling an API to load more data, or refresh whole page.
onRefresh: reload,
maximumPullLength: MAXIMUM_PULL_LENGTH,
refreshThreshold: REFRESH_THRESHOLD,
isDisabled: !isReady
});
return (
<div
style={{
top: (isRefreshing ? REFRESH_THRESHOLD : pullPosition) / 3,
opacity: isRefreshing || pullPosition > 0 ? 1 : 0
}}
className='bg-base-100 fixed inset-x-1/2 z-30 h-8 w-8 -translate-x-1/2 rounded-full p-2 shadow'
>
<div
className={`h-full w-full ${isRefreshing ? 'animate-spin' : ''}`}
style={!isRefreshing ? { transform: `rotate(${pullPosition}deg)` } : {}}
>
<AnySpinnerSVGIconComponentWorksHere className='h-full w-full' />
</div>
</div>
);
}
type UsePullToRefreshParams = {
onRefresh: () => void;
maximumPullLength?: number;
refreshThreshold?: number;
isDisabled?: boolean;
};
onRefresh
(required): refresh callback function run when pull event end.maximumPullLength
: limit how far the refresh icon was pulled down.refreshThreshold
: pullPosition
that will trigger onRefresh
function.isDisabled
: disabling pull function in case the onRefresh
function is not ready to run.type UsePullToRefreshReturn = {
isRefreshing: boolean;
pullPosition: number;
};
isRefreshing
: indicate refresh callback function is running.pullPosition
: current pull gesture position.MIT License © Senbonzakura1234
2.4.1
FAQs
A simple React custom hook for pull-to-refresh function that support NextJs
The npm package use-pull-to-refresh receives a total of 1,338 weekly downloads. As such, use-pull-to-refresh popularity was classified as popular.
We found that use-pull-to-refresh demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.