drf-react-by-schema
Version:
Components and Tools for building a React App having Django Rest Framework (DRF) as server
27 lines (26 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
function useWhyDidYouUpdate(name, props) {
const previousProps = (0, react_1.useRef)({});
(0, react_1.useEffect)(() => {
if (previousProps.current) {
const allKeys = new Set([...Object.keys(previousProps.current), ...Object.keys(props)]);
const changes = {};
allKeys.forEach((key) => {
var _a, _b;
if (((_a = previousProps.current) === null || _a === void 0 ? void 0 : _a[key]) !== props[key]) {
changes[key] = {
from: (_b = previousProps.current) === null || _b === void 0 ? void 0 : _b[key],
to: props[key],
};
}
});
if (Object.keys(changes).length > 0) {
console.log('[why-did-you-update]', name, changes);
}
}
previousProps.current = props;
});
}
exports.default = useWhyDidYouUpdate;