dydx-v4-web/src/hooks/useIsFirstRender.ts
James Jia - Test 4b86068d8f
Initial commit
2023-09-08 13:52:13 -07:00

17 lines
434 B
TypeScript

import { useRef, useEffect } from 'react';
/**
* indicate whether the current render is the first render (when the component was mounted)
* @returns {boolean} flag to determine first render.
* @note Using useRef hook to avoid the extra rerender.
*/
export const useIsFirstRender = () => {
const isFirstRender = useRef(true);
useEffect(() => {
isFirstRender.current = false;
}, []);
return isFirstRender.current;
};