mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
12 lines
214 B
TypeScript
12 lines
214 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
|
|
export default function usePrevious<T>(state: T): T | undefined {
|
|
const ref = useRef<T>();
|
|
|
|
useEffect(() => {
|
|
ref.current = state;
|
|
});
|
|
|
|
return ref.current;
|
|
}
|