ImEX and App Improvements.

This commit is contained in:
Patrick Fic
2024-03-15 09:29:49 -07:00
parent 7e01f667b3
commit f279fc1e81
16 changed files with 141 additions and 88 deletions

View File

@@ -0,0 +1,37 @@
import { useEffect, useRef } from 'react';
const usePrevious = (value, initialValue) => {
const ref = useRef(initialValue);
useEffect(() => {
ref.current = value;
});
return ref.current;
};
const useEffectDebugger = (effectHook, dependencies, dependencyNames = []) => {
const previousDeps = usePrevious(dependencies, []);
const changedDeps = dependencies.reduce((accum, dependency, index) => {
if (dependency !== previousDeps[index]) {
const keyName = dependencyNames[index] || index;
return {
...accum,
[keyName]: {
before: previousDeps[index],
after: dependency,
},
};
}
return accum;
}, {});
if (Object.keys(changedDeps).length) {
console.log('[use-effect-debugger] ', changedDeps);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(effectHook, dependencies);
};
export default useEffectDebugger;