mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: permissions service full access.
This commit is contained in:
@@ -6,4 +6,6 @@ export * from './useWhen';
|
||||
export * from './useRequestPdf';
|
||||
export * from './useAsync';
|
||||
export * from './useIntersectionObserver';
|
||||
export * from './useAbilityContext';
|
||||
export * from './useAbilityContext';
|
||||
export * from './useCustomCompareEffect';
|
||||
export * from './useDeepCompareEffect';
|
||||
|
||||
44
src/hooks/utils/useCustomCompareEffect.ts
Normal file
44
src/hooks/utils/useCustomCompareEffect.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { DependencyList, EffectCallback, useEffect, useRef } from 'react';
|
||||
|
||||
const isPrimitive = (val: any) => val !== Object(val);
|
||||
|
||||
type DepsEqualFnType<TDeps extends DependencyList> = (
|
||||
prevDeps: TDeps,
|
||||
nextDeps: TDeps,
|
||||
) => boolean;
|
||||
|
||||
const useCustomCompareEffect = <TDeps extends DependencyList>(
|
||||
effect: EffectCallback,
|
||||
deps: TDeps,
|
||||
depsEqual: DepsEqualFnType<TDeps>,
|
||||
) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!(deps instanceof Array) || !deps.length) {
|
||||
console.warn(
|
||||
'`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead.',
|
||||
);
|
||||
}
|
||||
|
||||
if (deps.every(isPrimitive)) {
|
||||
console.warn(
|
||||
'`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.',
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof depsEqual !== 'function') {
|
||||
console.warn(
|
||||
'`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const ref = useRef<TDeps | undefined>(undefined);
|
||||
|
||||
if (!ref.current || !depsEqual(deps, ref.current)) {
|
||||
ref.current = deps;
|
||||
}
|
||||
|
||||
useEffect(effect, ref.current);
|
||||
};
|
||||
|
||||
export { useCustomCompareEffect };
|
||||
24
src/hooks/utils/useDeepCompareEffect.ts
Normal file
24
src/hooks/utils/useDeepCompareEffect.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { DependencyList, EffectCallback } from 'react';
|
||||
import isDeepEqualReact from 'fast-deep-equal/react';
|
||||
import { useCustomCompareEffect } from './useCustomCompareEffect';
|
||||
|
||||
const isPrimitive = (val: any) => val !== Object(val);
|
||||
|
||||
const useDeepCompareEffect = (effect: EffectCallback, deps: DependencyList) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!(deps instanceof Array) || !deps.length) {
|
||||
console.warn(
|
||||
'`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.',
|
||||
);
|
||||
}
|
||||
|
||||
if (deps.every(isPrimitive)) {
|
||||
console.warn(
|
||||
'`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.',
|
||||
);
|
||||
}
|
||||
}
|
||||
useCustomCompareEffect(effect, deps, isDeepEqualReact);
|
||||
};
|
||||
|
||||
export { useDeepCompareEffect };
|
||||
Reference in New Issue
Block a user