This a doubt I have regarding the best practice when pushing a new object in an array of objects via setState.
In the below implementation the ‘prevObjects’ are being spread into the new array to set the state. This passes the references of the old objects, but does not mutate the array or the objects. Hence does that mean the below implementation is good? It is working, but could it be problematic in some edge cases?
const [objArray, setObjArray] = useState([{ name: John }, { name: Jane }]);
setObjArray((prevObjects) => [...prevObjects, newObject])