UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

26 lines (21 loc) 649 B
/** * Copyright IBM Corp. 2020, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; var React = require('react'); /** * 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 = React.useRef(undefined); React.useEffect(() => { ref.current = value; }); return ref.current; }; exports.usePreviousValue = usePreviousValue;