Created
April 13, 2019 08:49
-
-
Save ohansemmanuel/d050d65e0069a0ecaa7fdac247c1ef29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ArrayDep = () => { | |
const [randomNumber, setRandomNumber] = useState(0) | |
const [effectLogs, setEffectLogs] = useState([]) | |
useLayoutEffect( | |
() => { | |
setEffectLogs(prevEffectLogs => [...prevEffectLogs, 'effect fn has been invoked']) | |
}, | |
[randomNumber] | |
) | |
return ( | |
<div> | |
<h1>{randomNumber}</h1> | |
<button | |
onClick={() => { | |
setRandomNumber(Math.random()) | |
}} | |
> | |
Generate random number! | |
</button> | |
<div> | |
{effectLogs.map((effect, index) => ( | |
<div key={index}>{'🍔'.repeat(index) + effect}</div> | |
))} | |
</div> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment