setstate get previous state code example
Example: usestate access previous state
const [arrayOfObjs, handleObjSelection] = useState([]);
// on a buttton for example
<button
onClick={selectedObj => handleObjSelection(
prevSelected => [...prevSelected, selectedObj],
))}
>