metaforecast/src/web/hooks.ts
2022-04-19 01:15:42 +03:00

28 lines
534 B
TypeScript

import React, { DependencyList, EffectCallback, useEffect } from "react";
export const useNoInitialEffect = (
effect: EffectCallback,
deps: DependencyList
) => {
const initial = React.useRef(true);
useEffect(() => {
if (initial.current) {
initial.current = false;
return;
}
return effect();
}, deps);
};
export const useIsFirstRender = (): boolean => {
const isFirst = React.useRef(true);
if (isFirst.current) {
isFirst.current = false;
return true;
}
return isFirst.current;
};