
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@noeg/usepolling
Advanced tools
A React hook for implementing polling functionality with configurable intervals, conditions, and callbacks.
npm install @noeg/usepolling
# or
yarn add @noeg/usepolling
# or
pnpm add @noeg/usepolling
import { usePolling } from '@noeg/usepolling'
function MyComponent() {
const { data, error, isLoading, startPolling, stopPolling } = usePolling({
// Required: Function that returns a Promise
fetcher: async () => {
const response = await fetch('https://api.example.com/data')
return response.json()
},
// Optional: Polling interval in milliseconds (default: 5000)
interval: 3000,
// Optional: Condition to stop polling (default: () => false)
condition: (data) => data.status === 'completed',
// Optional: Success callback
onSuccess: (data) => {
console.log('Data received:', data)
},
// Optional: Error callback
onError: (error) => {
console.error('Polling failed:', error)
},
// Optional: Start polling immediately (default: true)
immediate: true,
})
if (isLoading) {
return <div>Loading...</div>
}
if (error) {
return <div>Error: {error.message}</div>
}
return (
<div>
<pre>{JSON.stringify(data, null, 2)}</pre>
<button onClick={startPolling}>Start Polling</button>
<button onClick={stopPolling}>Stop Polling</button>
</div>
)
}
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
fetcher | () => Promise<T> | Yes | - | Async function that fetches data |
interval | number | No | 5000 | Polling interval in milliseconds |
condition | (data: T) => boolean | No | () => false | Function to determine when to stop polling |
onSuccess | (data: T) => void | No | - | Callback function called on successful fetch |
onError | (error: Error) => void | No | - | Callback function called on fetch error |
immediate | boolean | No | true | Whether to start polling immediately |
| Property | Type | Description |
|---|---|---|
data | T | null | The latest data received from the fetcher |
error | Error | null | Error object if the last fetch failed |
isLoading | boolean | Whether a fetch is in progress |
startPolling | () => void | Function to manually start polling |
stopPolling | () => void | Function to manually stop polling |
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
React hooks to fetch data with polling
We found that @noeg/usepolling 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
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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.