struct-ui-components
Version:
A collection of reusable, customizable React components built with TypeScript, Tailwind CSS, and Storybook. Designed for modern UI development with flexibility and scalability.
14 lines (10 loc) • 323 B
text/typescript
import { useRef } from "react";
export const usePrevious = <T>(value: T): T | undefined => {
const currentRef = useRef<T>(value);
const previousRef = useRef<T>();
if (currentRef.current !== value) {
previousRef.current = currentRef.current;
currentRef.current = value;
}
return previousRef.current;
};