You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
307 B

import { useRef, useEffect } from 'react';
export default function usePrevious<T>(current: T): {
current: T;
} {
const ref = useRef<T>(current);
// will be updated on the next render
useEffect(() => {
ref.current = current;
});
// return the existing current (pre render)
return ref;
}