I want to get a JSON from a films API, I get the datas in the variable "data", but my array "allFilms" still empty even after the datas are loaded... (see the code below), Why my array is still empty please ?
const [allFilms, setAllFilms] = useState([]);
const [pending, setPending] = useState(true);
const [activePage, setActivePage] = useState(1)
const url = `https://api.themoviedb.org/3/movie/top_rated?api_key=${process.env.REACT_APP_API_KEY}&language=fr&page=${activePage}`;
useEffect(() => {
loadAllFilms();
}, []);
async function loadAllFilms() {
try {
const data = await axios.get(url);
console.log("data ", data); **<--- THIS CONSOLE.LOG GOT THE DATA**
setAllFilms(data);
console.log("allfilms ", allFilms); **<--- THIS CONSOLE.LOG IS EMPTY**
setPending(false);
} catch (error) {
console.error(error);
}
};