0

I was wondering why I get an empty array despite I've used setCategory but If I print (res.data.category), there are data inside this.

If you know anything about this, Thanks for your help.

const [category, setCategory] = useState([]);


    var listItems = '';
    useEffect(() => {

axios.get(`/api/getCategory`).then(res => {

if (res.data.status === 200) {
                    setCategory(res.data.category);
                    console.log(res.data.category);

                }
            });
     
    }, []);

1

Drew Reese
  • 103,803
  • 12
  • 69
  • 96
gabriel
  • 11
  • 2

0 Answers0