【发布时间】:2018-11-09 11:27:01
【问题描述】:
我有以下设置:
- aws-amplify-react
- 应用同步
- 创建反应应用程序
并遵循此文档:https://aws.github.io/aws-amplify/media/api_guide#connect
与文档中一样,在返回正确数据之前,渲染它会给我 2x undefined 数据。这会破坏应用程序,因为无法访问嵌套字段(在我的示例中,例如 getRoom.id)。
组件示例:
export const AppSyncTest = () => (
<Connect query={graphqlOperation(query)}>
{({ data: { getRoom } }) => {
console.log(getRoom); // returns undefined 2x before data is there
if (!getRoom) { // without this, app breaks
return 'why? (can even happen if loading is false)';
}
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">Welcome to IntelliFM WebApp</h1>
</header>
<p className="App-intro">
Found room {getRoom.id} with label {getRoom.label} and description{' '}
{getRoom.description}
</p>
</div>
);
}}
</Connect>
);
【问题讨论】:
标签: graphql aws-appsync aws-amplify