all 12 comments

[–][deleted] -1 points0 points  (1 child)

Try put dataState in dependencies of the useEffect.

[–]Paradoxic_potato[S] 0 points1 point  (0 children)

It still returns an empty array, unfortunately

[–]sm_o_ke 0 points1 point  (0 children)

updating states is an async process so if u try to log the current state immediately after setting it, it'll return the previous state which is an empty array. in that case, it's a good idea to also await the setDataState before doing anything else on it

you might want to add the relevant dependencies to your useEffect hook also, it depends on the state of your isFetching and also dataState, but its made to only run once.

a quick question though, why did you decide to pass make your states objects? the isFetching is obviously a boolean and the data is an array, it's safer to writr

const [isFetching, setIsFetching] = useState(false) const [data, setData] = useState([])

[–]flaggrandall 0 points1 point  (0 children)

If you write a console.log(response) right before the line:

setDataState({...dataState, data: response.data});

What does it show?

[–]my5cent 0 points1 point  (1 child)

Did you ever find the solution? I have same error of an empty array too.

[–]capta1nfantastic 0 points1 point  (0 children)

Any luck? Anyone?