import React from "react";
export function useWhyDidYouUpdate(label, props) {
    const previousProps = React.useRef(null);
    React.useEffect(() => {
        if (previousProps.current) {
            const allKeys = Object.keys({
                ...previousProps.current,
                ...props,
            });
            const changesObj = {};
            for (const key of allKeys) {
                if (previousProps.current[key] !== props[key]) {
                    changesObj[key] = {
                        from: previousProps.current[key],
                        to: props[key],
                    };
                }
            }
            if (Object.keys(changesObj).length) {
                console.log("[why-did-you-update]", label, changesObj);
            }
        }
        previousProps.current = props;
    });
}
