A React custom Hook is a JavaScript function whose name starts with use and that can call other Hooks. It lets components reuse behavior—such as keeping a counter and advancing it on an interval—without putting all that logic in each component. Each call gets its own state; a custom Hook shares logic, not a shared state value.
What a custom Hook does
React describes custom Hooks as a way to share logic between components. A Hook such as useCounter can hold state and coordinate an Effect, while the component that calls it decides how to display the result. The React guide to reusing logic with custom Hooks demonstrates this idea with a counter.
The use prefix is meaningful: it identifies the function as a Hook, so it follows the Rules of Hooks and can call built-in or other custom Hooks. A clear, behavior-specific name also tells callers what the logic is for.
Extract a counter into useCounter
This example keeps a count in state, increments it once per second, and returns the count for rendering:
#1 Best Overall
import { useEffect, useState } from 'react';
export function useCounter() {
const [count, setCount] = useState(0);
useEffect(() => {
const id = setInterval(() => {
setCount(c => c + 1);
}, 1000);
return () => clearInterval(id);
}, []);
return count;
}
export default function Counter() {
const count = useCounter();
return <h1>Seconds passed: {count}</h1>;
}
How the pieces work
useState(0)gives this Hook call a count initialized to zero.useEffectstarts an interval after the component is set up. The interval callssetCount(c => c + 1), a functional update that calculates the next value from the previous value.- The Effect returns cleanup that clears the interval when the component using the Hook is removed.
useCounterreturns the current count;Counterhandles presentation.
The empty dependency array means this Effect does not depend on changing reactive values from the component. For guidance on Effects and their setup and cleanup behavior, see React’s useEffect reference.
Custom Hook state is not shared automatically
If two components each call useCounter(), each call has its own independent count and interval. Reusing the Hook reuses the behavior, not the state instance. When components need to reflect one coordinated value, put that state in their closest common parent and pass it to them through props. React explains this approach in its guide to sharing state between components.
Call Hooks only at the top level
Call useCounter at the top level of a function component or another custom Hook. Do not call it conditionally, in a loop, in a nested function, or inside an event handler. The same rule applies to built-in Hooks such as useState and useEffect. See React’s Rules of Hooks guidance.
Choose a focused name and responsibility
Name a custom Hook for the concrete behavior it provides: React gives examples such as useData, useChatRoom, and useMediaQuery. Keep its API focused enough that a caller can understand what it does.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Rank #3
Avoid generic wrappers such as useMount that merely hide an Effect behind a lifecycle-sounding name. Such a wrapper can obscure which reactive values an Effect uses and make dependency mistakes harder for the Hooks linter to flag. When the behavior is synchronization with an external system, a focused Hook such as useChatRoom can make that purpose explicit.
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




