Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!