Let's assume that we generate a random value by clicking a button and we want to show the previous values as well.
javascriptimport React, { useState } from 'react'; const Random = () => { const [numbers, setNumbers] = useState(0); return( <div className = 'Random'> {numbers} <button onClick = {() => setNumbers(previous => `${previous} ${Math.random()}`)}>Generate</button> </div> ); } export default Random;
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.