mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
41 lines
927 B
JavaScript
41 lines
927 B
JavaScript
import {useRef, useEffect} from 'react';
|
|
import useAsync from './async';
|
|
import useAutofocus from './useAutofocus';
|
|
|
|
// import use from 'async';
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
|
|
export function useIsValuePassed(value, compatatorValue) {
|
|
const cache = useRef([value]);
|
|
|
|
useEffect(() => {
|
|
if (cache.current.indexOf(value) === -1) {
|
|
cache.current.push(value);
|
|
}
|
|
}, [value]);
|
|
|
|
return cache.current.indexOf(compatatorValue) !== -1;
|
|
}
|
|
|
|
export {
|
|
useAsync,
|
|
useAutofocus,
|
|
} |