Axios returns empty array
Hi, i'm a little new to react and i have a problem with getting data from my django REST backend. i'm following a tutorial on how to do it but for some reason axios returns an empty array. Here's the code:
import {useEffect, useState} from 'react';
import axios from 'axios';
import { tokenConfig }from './auth';
import React from 'react'
const useCollectData = (url, getState) => {
const [fetch, setFetching] = useState({ isFetching: false });
const [dataState, setDataState] = useState({ data: [] });
const [apiurl] = useState(url);
useEffect(() => {
const fetchDataFromApi = async () => {
try{
setFetching({isFetching: true})
const response = await axios.get(apiurl, tokenConfig(getState))
setDataState({...dataState, data: response.data});
} catch (e) {
setFetching({ ...fetch, isFetching: true})
}
};
fetchDataFromApi();
}, []);
return [dataState]
};
export default useCollectData
Here's what i get when i console.log(dataState):
And here's what i get when i make the request through Insomnia:
Posted Dec 28, 2020, 2:24 AM UTC
116