Axios returns empty array

Needs Help

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):

https://ibb.co/0yTckrF

​

And here's what i get when i make the request through Insomnia:

https://ibb.co/StpT93j

Posted Dec 28, 2020, 2:24 AM UTC

116
Loading comments…