Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
React access to value api

I'm creating a book finder app using google book api. But I can get from the api only the kind value and not the title and the authors I leave here the code

    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>
      </>
    );
    };

here the 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"
        ],

thanks for the help

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just add if after useEffect, and set by default state books null

const [books, setBooks] = useState(null)
// Your code
if (!books) return <h1>Loading...</h1>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda