
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
react-hook-list
Advanced tools
A set of React hooks to make life easier.
import { useTimeout } from 'react-hook-list';
useTimeout(callback: CallbackFn, ms?: number): [CancelFn, RestartFn]
React-safe wrapper around setTimeout()
const [cancel, restart] = useTimeout(
() => console.log('callback!'),
5000
);
return (
<>
<button onClick={restart}>Restart timer</button>
<button onClick={cancel}>Cancel timer</button>
<>
)
Calling cancel()
clears any in-progress timer.
Calling restart()
restarts the timer - any in-progress timer is cancelled.
Passing null
or undefined
as the callback triggers a single re-render when the timer fires.
// this will force the component to re-render after 5 seconds
useTimeout(null, 5000);
import { useInterval } from 'react-hook-list'
useInterval(callback: CallbackFn, ms?: number): [CancelFn, RestartFn]
React-safe wrapper around setInterval()
const [cancel, restart] = useInterval(
() => console.log('callback!'),
2000
);
return (
<>
<button onClick={restart}>Restart timer</button>
<button onClick={cancel}>Cancel timer</button>
<>
)
Calling cancel()
stops any in-progress timer.
Calling restart()
restarts the timer - any in-progress timer is cancelled.
Passing null
or undefined
as the callback triggers a re-render each time the timer fires.
// this will force the component to re-render every two seconds
useInterval(null, 2000);
Simple Clock
import React from 'react';
import { useInterval } from 'react-hook-list';
export const SimpleClock = () => {
useInterval(null, 1000);
return <>{new Date().toLocaleTimeString()}</>;
};
import { useAPI } from 'react-hook-list'
useAPI<T>(url: string | URL): [data: T, error: Error, isLoading: boolean, refresh: Function]
Simple wrapper around a React-safe call to a JSON API.
type MyList = {
values: number[];
};
const [data, error, isLoading, refresh] = useAPI<MyList>(
'https://example.com/api/get-list'
);
console.log({
data,
error,
isLoading,
});
return (
<>
<button onClick={refresh}>Refresh</button>
</>
);
Combine with useInterval
to poll an API endpoint:
type MyList = {
values: number[];
};
const [data, error, isLoading, refresh] = useAPI<MyList>(
'https://example.com/api/get-list'
);
useInterval(refresh, 10e3);
console.log({
data,
error,
isLoading,
});
FAQs
Simple react-hook utilities
The npm package react-hook-list receives a total of 2 weekly downloads. As such, react-hook-list popularity was classified as not popular.
We found that react-hook-list 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
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.