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
  • 165,259
  • 14
  • 153
  • 181
gabriel
  • 41
  • 2

0 Answers0