Estoy tratando de obtener json en axios
pero si uso mi código, se produjo este error y advertencia
¿Cómo puedo obtener respuesta.json?
response.json no es una función
este es mi codigo
// url="https://yts.lt/api/v2/list_movies.json?sort_by=like_count&order_by=desc&limit=5" url is props useEffect(() => { axios .get(url) .then((response) => response.json()) .then((json) => { console.log('json', json); setData(json.data.movies); }) .catch((error) => { console.log(error); }); }, []);El objeto de respuesta de axios almacena sus datos en response.data .
useEffect(() => { axios .get(url) .then((response) => { const json = response.data; console.log('json', json); setData(json.data.movies); }) .catch((error) => { console.log(error); }); }, []);Utilizar este:
useEffect(() => { axios .get(url) .then((response) => response.data) .then((json) => { console.log('json', json); setData(json.data.movies); }) .catch((error) => { console.log(error); }); }, []);