bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/utils/hooks/index.ts

20 lines
431 B
TypeScript
Raw Normal View History

import { useEffect, useRef } from 'react';
2022-05-31 02:49:19 +08:00
/**
* Custom hook to get previous value. It can be used,
* for example, to get previous props or state.
* @param {*} value Value to be tracked
2022-05-31 02:49:19 +08:00
* @returns The previous value.
*/
export const usePreviousValue = <T = unknown>(value: T) => {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
};
export default {
2022-05-31 02:49:19 +08:00
usePreviousValue,
};