1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/hooks/usePrevious.ts

18 lines
468 B
TypeScript
Raw Normal View History

2024-02-13 01:09:08 -05:00
import { useEffect, useRef } from 'react';
/**
* A hook that returns the previous value of a stateful value.
* @param value A stateful value created by a `useState` hook.
* @param initialValue The default value.
* @returns The previous value.
*/
export function usePrevious<T>(value: T, initialValue?: T): T | undefined {
const ref = useRef<T | undefined>(initialValue);
useEffect(() => {
ref.current = value;
});
return ref.current;
}