SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const ArrayDep = () => {
  2.     const [randomNumber, setRandomNumber] = useState(0)
  3.     const [effectLogs, setEffectLogs] = useState([])
  4.  
  5.     useLayoutEffect(
  6.       () => {
  7.         setEffectLogs(prevEffectLogs => [...prevEffectLogs, 'effect fn has been invoked'])
  8.       },
  9.       [randomNumber]
  10.     )
  11.  
  12.     return (
  13.       <div>
  14.         <h1>{randomNumber}</h1>
  15.         <button
  16.           onClick={() => {
  17.             setRandomNumber(Math.random())
  18.           }}
  19.         >
  20.           Generate random number!
  21.         </button>
  22.         <div>
  23.           {effectLogs.map((effect, index) => (
  24.             <div key={index}>{'🍔'.repeat(index) + effect}</div>
  25.           ))}
  26.         </div>
  27.       </div>
  28.     )
  29.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top