Signed-off-by: Bernard Setz <bernard.setz@portainer.io> Co-authored-by: bernard-portainer <bernard.setz@portainer.io> Co-authored-by: Ali <83188384+testA113@users.noreply.github.com> Co-authored-by: Yajith Dayarathna <yajith.dayarathna@portainer.io> Co-authored-by: Chaim Lev-Ari <chiptus@users.noreply.github.com> Co-authored-by: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Co-authored-by: Josiah Clumont <josiah.clumont@portainer.io> Co-authored-by: Dakota Walsh <101994734+dakota-portainer@users.noreply.github.com>
21 lines
513 B
TypeScript
21 lines
513 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
|
|
/**
|
|
* Like `useEffect`, but skips the callback on the initial render.
|
|
* Only runs when a dependency changes after the component has mounted.
|
|
*/
|
|
export function useUpdateEffect(
|
|
fn: () => void,
|
|
deps: React.DependencyList
|
|
): void {
|
|
const isFirstRender = useRef(true);
|
|
useEffect(() => {
|
|
if (isFirstRender.current) {
|
|
isFirstRender.current = false;
|
|
return;
|
|
}
|
|
fn();
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, deps);
|
|
}
|