#react-native #aws-amplify #mobile-application
#react-native #aws-amplify #mobile-application
Вопрос:
Эй, я создаю мессенджер с помощью react native, expo и aws amplify. Это мой фрагмент кода из файла UserItem
import { Auth } from 'aws-amplify'; import { DataStore } from '@aws-amplify/datastore'; import { ChatRoom, User, ChatRoomUser } from '../../src/models'; export default function UserItem({ user }) { const navigation = useNavigation(); const onPress = async () =gt; { const newChatRoom = await DataStore.save(new ChatRoom({ newMessages: 0 })); const authUser = await Auth.currentAuthenticatedUser(); const dbUser = await DataStore.query(User, authUser.attributes.sub); new ChatRoomUser({ user, chatroom: newChatRoom, }) ); navigation.navigate('ChatRoom', { id: newChatRoom.id }); }; return ( lt;Pressable onPress={onPress} style={styles.container}gt; lt;Image source={{ uri: user.imageUri }} style={styles.image} /gt; lt;View style={styles.rightContainer}gt; lt;View style={styles.row}gt; lt;Text style={styles.name}gt;{user.name}lt;/Textgt; lt;/Viewgt; lt;/Viewgt; lt;/Pressablegt; ); }
и это мой код экрана пользователя
import React, { useState, useEffect } from 'react'; import { View, StyleSheet, FlatList } from 'react-native'; import { DataStore } from '@aws-amplify/datastore'; import UserItem from '../components/UserItem'; import { User } from '../src/models'; export default function UsersScreen() { const [users, setUsers] = useStatelt;User[]gt;([]); useEffect(() =gt; { DataStore.query(User).then(setUsers); }, []); return ( lt;View style={styles.page}gt; lt;FlatList data={users} renderItem={({ item }) =gt; lt;UserItem user={item} /gt;} showsVerticalScrollIndicator={false} /gt; lt;/Viewgt; ); }
но я получаю 2 сообщения в консоли
INFO] 37:36.850 Reachability - subscribing to reachability in React Native [INFO] 37:37.118 Reachability - Notifying reachability change true Possible Unhandled Promise Rejection (id: 0): Object { "data": Object { "syncUsers": null, }, "errors": Array [ Object { "locations": null, "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'User' (/syncUsers/items[0]/createdAt)",
I have tried deleting my users from DynamoDb and then added new users in it but the error persists. I think I have to reset my aws-amplify json file but I do not how.