score:0

setUsers((prevStateOfUsers) => [...prevStateOfUsers, { name: 'Alexandre'} ]);

score:0

import React, { useState, useEffect } from 'react';

function Example() {
  const [users, setUsers] = useState([]);

  useEffect(() => {
    setUsers([...users, { name: 'Alexandre'} ]);
    console.log(users);
  }, []);

  return (
    <div>
      something...
    </div>
  );
}

score:0

import React, { useState, useEffect } from 'react';

 const Component = () => {

  const [users, setUsers] = useState([]);

  useEffect(() => {
    setUsers([...users, {
       name: 'Alexandre',
    }]);
  }, []);

  return (
   your code...
  );
};

Related Query

More Query from same tag