I initialised state like this:
const [titles, setTitles] = useState([])
I'm appending another array of items data.titles
to the array titles
in a loop like this:
setTitles(titles => [...titles, data.titles])
and I have also tried this:
setTitles([...titles, data.titles])
but both don't seem to work, because when I'm printing titles
in the console after the loop is done, an empty array is displayed. What am I missing here?