Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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])
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js do every x seconds 
Javascript :: javascript decimal to string 
Javascript :: how to get clicked element class in jquery 
Javascript :: access to xmlhttprequest at from origin http localhost:3000 has been blocked by cors policy 
Javascript :: javascript object dont sort 
Javascript :: validate age javascript 
Javascript :: javascript empty cache and hard reload 
Javascript :: convert number to string date js 
Javascript :: vue router 404 page 
Javascript :: replace regex javascript 
Javascript :: javascript: get the url without query string 
Javascript :: load a page with ajax 
Javascript :: jquery modify style attribute 
Javascript :: number pyramid javascript 
Javascript :: js check if function exists 
Javascript :: generate a sequence numbers between a range javascript 
Javascript :: a <route is only ever to be used as the child of <routes element" 
Javascript :: ajax load spesific element from another page 
Javascript :: how to convert a JavaScript iterator to array 
Javascript :: how to make slide js in owl carousel auto 
Javascript :: how to return ascending array using for loop in js 
Javascript :: angular maxlength directive input type number 
Javascript :: js check if two array have the same element 
Javascript :: today in moment 
Javascript :: javascript switch 
Javascript :: javascript execute string code 
Javascript :: js import jquery 
Javascript :: Javscript Add days on Date 
Javascript :: javascript transpose rows to columns 
Javascript :: select remove option jquery 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =