chelo78

CounterUseRef

Oct 21st, 2021
630
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState, useEffect, useRef} from 'react'
  2. import {Card} from 'antd'
  3.  
  4. function Counter() {
  5.   const [count, setCount]=useState(0);
  6.  
  7.   useEffect(()=>{
  8.     prevCountRef.current=count;
  9.   })
  10.   const prevCount=prevCountRef.current;
  11.  
  12.   return <Card> Now: {count}, before {prevCount}</Card>;
  13. }
  14.  
  15. export default Counter;
  16.  
RAW Paste Data