UNPKG

@carbon/ibm-products

Version:
31 lines (29 loc) 918 B
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ require("../../../_virtual/_rolldown/runtime.js"); let react = require("react"); //#region src/global/js/hooks/usePreviousValue.js /** * Copyright IBM Corp. 2021, 2021 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ /** * Returns the previous state value included in the param * @param {object} value - The current value of any type. * @returns {T | undefined} - The previous value of the same type, or undefined if there is none */ const usePreviousValue = (value) => { const ref = (0, react.useRef)(void 0); (0, react.useEffect)(() => { ref.current = value; }); return ref.current; }; //#endregion exports.usePreviousValue = usePreviousValue;