skip to Main Content

State variable does not change inside useEffect – React native

In the following useEffect, data is fetched and is logged successfully: const [allBooks, setAllBooks] = useState([]); useEffect(() => { axios.get('/all_books').then(res => { setAllBooks(res.data); console.log(res.data) //console.log(allBooks) }).catch(error => { console.log(error); }); }, []); //... return( {allBooks.length > 0 ? ( <div…

VIEW QUESTION

Resolve promise.all inside a useEffect – Javascript

I have a simple useEffect in my component to fetch data from 3 API calls: useEffect(() => { Promise.all([ fetch(`${baseUrl}/counts?entity=color`), fetch(`${baseUrl}/counts?entity=brand`), fetch(`${baseUrl}/counts?entity=category`) ]).then(([x, y, z])=> { console.log(x.json(), y.json(), z.json()); }); }, []); I'm expecting the actual data I get from…

VIEW QUESTION
Back To Top
Search