Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
i CAnt display items from appsync api

import logo from './logo.svg'; i need to list items from my appsync api in my react app ...i cant display as it says the error its undefined ...which i mentioned bellow the code..i know my code is wrong can somebody guide me

import React, { useState } from "react";
import { API, graphqlOperation } from 'aws-amplify';
import { listTestModels } from "./graphql/queries/list";
import './App.css';


function App() {

  const [list, setBook] = useState(null);

  const getBook = async () => {
    // make a call to appsync api
    const list = await API.graphql(graphqlOperation(listTestModels));

    setBook(list.data.listTestModels.items);

  }

  const viewBook = () => {
    if (list) {
**it shows error after this **
      return (<article>
        <h3>{list.data.listTestModels.items}</h3>
        <p>{list.Location}</p>
        <p>{list.Email}</p>
      </article>)
    }
  }

  return (
    <div>
      <section className="book-section">
        <button onClick={() => getBook()}>Get book details</button>
        <hr />
        {viewBook()}
      </section>
    </div>
  );
}

export default App;```


**it shows error App.js:24 Uncaught TypeError: Cannot read properties of undefined (reading 'listTestModels')**
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

list.data is undefined. Change the condition to list && list.data

const viewBook = () => {
    if (list  && list.data) {...}
}

But if the data key doesn't exist in the list object . It will never render the viewBook.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda