2019-11-08 16:30:11 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-11-06 18:25:37 +00:00
|
|
|
import { useRef, useEffect } from 'react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use Previous from https://usehooks.com/usePrevious/.
|
|
|
|
* @param {mixed} value
|
|
|
|
*/
|
|
|
|
export const usePrevious = ( value ) => {
|
|
|
|
const ref = useRef();
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
ref.current = value;
|
|
|
|
}, [ value ] );
|
|
|
|
|
|
|
|
return ref.current;
|
|
|
|
};
|