What is the best way of iterating through a JSON response, and inserting specific elements of the JSON element into an array (assuming I'm using React hooks). This is my attempt, but the issue is the first time I execute the function, I get no output, the second time, I get the intended output, and then the consequent executions keep on adding to the datelist array(size doubles every time).
const get = () => {
fetch('/test')
.then(response => response.json())
.then(data => {setDates(data)})
setDatelist([]);
setDatelist(datelist => [...datelist, dates.map(date => date.start["dateTime"])]);
console.log(datelist);
}