Skip to content

Instantly share code, notes, and snippets.

@ohansemmanuel
Created April 13, 2019 08:16
Show Gist options
  • Select an option

  • Save ohansemmanuel/bc55d5feb0835c39d4a01532759778e8 to your computer and use it in GitHub Desktop.

Select an option

Save ohansemmanuel/bc55d5feb0835c39d4a01532759778e8 to your computer and use it in GitHub Desktop.
const ArrayDepMount = () => {
const [randomNumber, setRandomNumber] = useState(0)
const [effectLogs, setEffectLogs] = useState([])
useEffect(
() => {
setEffectLogs(prevEffectLogs => [...prevEffectLogs, 'effect fn has been invoked'])
},
[]
)
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