@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
23 lines (22 loc) • 618 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = usePreviousState;
var _react = require("react");
/**
*
* Can be used to get the previous state of a prop.
* This can be helpful when converting class components to functional
* where we don't have the `prevProps`.
*
* @param value New state of the
* @param initialValue Optional parameter for the inital state of the component
* @returns
*/
function usePreviousState(value, initialValue) {
var ref = (0, _react.useRef)(initialValue);
var prevValue = ref.current;
ref.current = value;
return prevValue;
}