How to get previous state with React Hooks

Let's assume that we generate a random value by clicking a button and we want to show the previous values as well.

import React, { useState } from 'react';

const Random = () => {
    const [numbers, setNumbers] = useState(0);

        <div className = 'Random'>
            <button onClick = {() => setNumbers(previous => `${previous} ${Math.random()}`)}>Generate</button>

export default Random;

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.