Useffect membandingkan nilai sebelumnya dengan saat ini
//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])
}
Embarrassed Echidna