Created
April 13, 2019 08:16
-
-
Save ohansemmanuel/bc55d5feb0835c39d4a01532759778e8 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 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