woocommerce/plugins/woocommerce-blocks/assets/js/base/hooks/use-previous.js

19 lines
316 B
JavaScript

/**
* External dependencies
*/
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;
};