Estoy creando una aplicación de búsqueda de libros usando la API de Google Book. Pero puedo obtener de la api solo el valor del tipo y no el título y los autores, aquí dejo el código.
const getData = async () => { const response = await axios.get(url); console.log(response); // 2) Passo funzione utile a fetchare dei dati dall'api con axios al url setBooks(response.data.items); }; useEffect(() => { // 3)Passo abbiamo settato il nuovo array dai dati presi da getData che li prendeva dall'api getData(); // Chiamata all'interno di una funzione in useEffect perche lo use effect non può essere asyncrono }, []); // Clean up cosi gli diciamo che vogliamo che venga chiamato solo al primo render se no va in loop senza return ( <> <ul> { books.map( el => { const {kind, id, title} = el return <li key={id} className="shadow"> <h5>{title}</h5> </li> }) } </ul> </> ); };aquí la API
"kind": "books#volumes", "totalItems": 2, "items": [ { "kind": "books#volume", "id": "5svUwAEACAAJ", "etag": "ag5tZElp08M", "selfLink": "https://www.googleapis.com/books/v1/volumes/5svUwAEACAAJ", "volumeInfo": { "title": "Year Book", "subtitle": "The Annual Supplement to the World Book Encyclopedia : the 1989 World Book : a Review of the Events of 1988", "authors": [ "World Book Encyclopedia" ],gracias por la ayuda
Simplemente agregue if después de useEffect , y configure de forma predeterminada los libros de estado null
const [books, setBooks] = useState(null) // Your code if (!books) return <h1>Loading...</h1>