useffect compare previous value to current
//Custom Hook
function usePrevious(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
}
// Use it in useEffect
const Component = (props) => {
const {receiveAmount, sendAmount } = props
const prevAmount = usePrevious(receiveAmount);
useEffect(() => {
if(prevAmount.receiveAmount !== receiveAmount) {
// process here
}
}, [receiveAmount])
}