mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
21 lines
526 B
TypeScript
21 lines
526 B
TypeScript
// @ts-nocheck
|
|
import { useRef, useEffect } from 'react';
|
|
|
|
/**
|
|
* A custom useEffect hook that only triggers on updates, not on initial mount
|
|
* Idea stolen from: https://stackoverflow.com/a/55075818/1526448
|
|
* @param {Function} effect
|
|
* @param {Array<any>} dependencies
|
|
*/
|
|
export function useUpdateEffect(effect, dependencies = []) {
|
|
const isInitialMount = useRef(true);
|
|
|
|
useEffect(() => {
|
|
if (isInitialMount.current) {
|
|
isInitialMount.current = false;
|
|
} else {
|
|
effect();
|
|
}
|
|
}, dependencies);
|
|
}
|