@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
18 lines (17 loc) • 511 B
JavaScript
import { useRef } from '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
*/
export default function usePreviousState(value, initialValue) {
const ref = useRef(initialValue);
const prevValue = ref.current;
ref.current = value;
return prevValue;
}