mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-01 17:51:23 +00:00
* Use callback funcs * Don't use idx to identify rows * Add debug function for finding why a component re-rendered * Do not pass 'control' through to each row * Prevent unnecessary re-rendering of table rows * Adjust order of operations for hooks * Keep props hidden * Use lightweight NumberInput * Use NumberInput elsewhere * Add comment * use rowId instead of idx * Generic row memos * Compare errors too * Fix for BomItemSubstituteRow * Adjust more forms * memoize quantity * Memoize build lines * Fix re-rendering issues for build allocation * Fix for useConsumeBuildLinesForm * Fix for transfer order table * Fix useReceiveLineItems * Remove memoized pattern * Fix row keys * Cleanup * Create useStockItems hook for memoizing items * Refactoring * More refactoring * Remove obj reference - preventing shallow comparison from working * Add error message to useWhyDidYouUpdate * Cleanup * Cleanup dead code * Adjust modal width * Change attr name * Remove autoFillFilters prop * Adjustments for serialized stock * Fix typing * Bump frontend version * Adjustments for playwright testing * Fix ref issue * Remove debug entry * Update CHANGELOG.md * Reintroduce index to table header * Refactor common component
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
/** Various debugging helper functions for development */
|
|
|
|
import { useEffect, useRef } from 'react';
|
|
|
|
/**
|
|
* A custom hook that logs the previous and current props of a component whenever it updates.
|
|
*/
|
|
export function useWhyDidYouUpdate(name: string, props: any) {
|
|
const previousProps = useRef({});
|
|
|
|
useEffect(() => {
|
|
console.error(
|
|
'useWhyDidYouUpdate should not be used in production code. It is intended for debugging purposes only.'
|
|
);
|
|
|
|
if (previousProps.current) {
|
|
const allKeys = Object.keys({ ...previousProps.current, ...props });
|
|
const changedProps: any = {};
|
|
|
|
allKeys.forEach((key) => {
|
|
if ((previousProps as any).current[key] !== props[key]) {
|
|
(changedProps as any)[key] = {
|
|
from: (previousProps as any).current[key],
|
|
to: props[key]
|
|
};
|
|
}
|
|
});
|
|
|
|
if (Object.keys(changedProps).length > 0) {
|
|
console.log(`[${name}] Changed props:`, changedProps);
|
|
}
|
|
}
|
|
|
|
previousProps.current = props;
|
|
});
|
|
}
|