score:1

Accepted answer
const [number, setNumber] = useState(0);

  const [list, setList] = useState([]);
  useEffect(() => {
    const interval = setInterval(
      () => setNumber(Math.floor(Math.random() * 50 + 1)),
      1000,
    );
    // clean up interval on unmount
    return () => {
      clearInterval(interval);
    };
  }, []);

  useEffect(() => {
    setList([...list, number])
  }, [number])
  return (
    <div>
      <p>{list}</p>
    </div>
  );


Related Query

More Query from same tag