@arolariu/components
Version:
🎨 70+ beautiful, accessible React components built on Base UI. TypeScript-first, CSS Modules styling, tree-shakeable, SSR-ready. Perfect for modern web apps, design systems & rapid prototyping. Zero config, maximum flexibility! ⚡
33 lines • 1.07 kB
TypeScript
/**
* Tracks and returns the previous value of a state or prop.
*
* @remarks
* This hook stores the value from the previous render cycle, allowing you to compare
* current and previous values. On the initial render, it returns `undefined` since
* there is no previous value yet.
*
* Useful for detecting changes, implementing undo functionality, or creating
* animations based on value transitions.
*
* @typeParam T - The type of the value being tracked.
* @param value - The current value to track.
* @returns The value from the previous render, or `undefined` on the first render.
*
* @example
* ```tsx
* function Counter() {
* const [count, setCount] = useState(0);
* const previousCount = usePrevious(count);
*
* return (
* <div>
* <p>Current: {count}</p>
* <p>Previous: {previousCount ?? "N/A"}</p>
* <button onClick={() => setCount(count + 1)}>Increment</button>
* </div>
* );
* }
* ```
*/
export declare function usePrevious<T>(value: T): T | undefined;
//# sourceMappingURL=usePrevious.d.ts.map