UNPKG

@sanity/form-builder

Version:
20 lines (18 loc) 601 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePrevious = usePrevious; var _react = require("react"); /** * A hook that returns the previous value of a component variable * This might be provided by React in the future (https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state) * @param value The value to track. Will return undefined for first render */ function usePrevious(value, initial) { var ref = (0, _react.useRef)(initial); (0, _react.useEffect)(() => { ref.current = value; }, [value]); return ref.current; }