TypeError: Cannot read property 'items' of undefined inside API react Connect component
See original GitHub issue** Which Category is your question related to? ** API
** What AWS Services are you utilizing? ** API (GraphQL AppSync) Auth
** Provide additional details e.g. code snippets ** Error:
My App.js:
import React, { Component } from 'react';
import './App.css';
import Amplify, { graphqlOperation } from "aws-amplify";
import { Connect } from "aws-amplify-react";
import awsmobile from './aws-exports';
Amplify.configure(awsmobile)
class App extends Component {
render() {
const ListView = ({ companies }) => (
<div>
<h3>All companies</h3>
<ul>
{companies.map(company => <li key={company.id}>{company.name} ({company.id})</li>)}
</ul>
</div>
);
const ListCompanys = `query ListCompanys {
listCompanys {
items {
id
name
}
}
}`;
return (
<div className="App">
<Connect query={graphqlOperation(ListCompanys)}>
{({ data: { listCompanys } }) => (
<ListView companies={listCompanys.items} />
)}
</Connect>
</div>
);
}
}
export default App;
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ReactJS - cannot read property 'items' of undefined
When I try to console.log(this.state.items) in the addItem method, I get this error. Uncaught TypeError: Cannot ...
Read more >How to Read React Errors (fix 'Cannot read property of ...
TypeError is the kind of error. There are a handful of built-in error types. · Cannot read property means the code was trying...
Read more >Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >Cannot read property 'reduce' of undefined in react-Reactjs
Coding example for the question TypeError: Cannot read property 'reduce' of undefined in react-Reactjs.
Read more >Can Not Read Properties of Undefined Reading Map in React ...
If you are looking at can not read properties of undefined reading map in react js error or map function is not displaying...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am having similar issues, the same query succeed with API.graphql call directly, but fail with Connect.
This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.