All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.js.helpers.useUnmountEffect.js Maven / Gradle / Ivy

Go to download

This library provides a set of common React components for use with the PatternFly reference implementation.

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useUnmountEffect = void 0;
const react_1 = require("react");
/**
 * A `useEffect`-like hook that only triggers when a component unmounts. Does not require a dependency list, as the effect callback will always be kept up to date.
 */
function useUnmountEffect(effect) {
    // Always use the latest effect callback so that it can reference the latest props and state.
    const effectRef = (0, react_1.useRef)(effect);
    effectRef.current = effect;
    // Trigger the effect callback when the component unmounts.
    (0, react_1.useEffect)(() => () => {
        effectRef.current();
    }, []);
}
exports.useUnmountEffect = useUnmountEffect;
//# sourceMappingURL=useUnmountEffect.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy