Closed Gaztoof closed 1 month ago
EDIT: It turns out Amplify isn't actually simply registering the first call. But I noticed the actual problem is that DataStore is so slow that it appears like that... After a few minutes and restarting the app, everything syncs... But, when calling functions like DataStore.save, it literally takes a whole minute to update a very simple element...
EDIT: Problem solved, turns out DataStore.query was being called repeatedly in a useEffect that was wrongly configurated. So it was getting spammed / overloaded and that's why it was so unresponsive! Here's the problematic code snippet: ` useEffect(() => { const checkUser = async () => { try { const currUser = await getCurrentUser(); const profiles = await DataStore.query(UserProfile, (profile) => profile.owner.eq(currUser.userId));
if(profiles.length > 0)
{
switch(profiles[0].profileType)
{
case 'CONSULTANT':
const consultantProfiles = await DataStore.query(ConsultantProfile, (profile) => profile.owner.eq(currUser.userId));
setConsultantProfile(consultantProfiles.length > 0 ? consultantProfiles[0] : null);
break;
case 'CONSULTANTCOMPANY':
const companyProfiles = await DataStore.query(ConsultantCompanyProfile, (profile) => profile.owner.eq(currUser.userId));
setCompanyProfile(companyProfiles.length > 0 ? companyProfiles[0] : null);
break;
case 'HR':
const hrProfiles = await DataStore.query(HRProfile, (profile) => profile.owner.eq(currUser.userId));
setCompanyProfile(hrProfiles.length > 0 ? hrProfiles[0] : null);
break;
}
}
setProfile(profiles.length > 0 ? profiles[0] : null);
} catch (e) {
console.log(e);
setProfile(null);
}
}
checkUser();
});`
The fix was simply to add a ", []" as a parameter in the useEffect, so, going from:
useEffect(() => { ...});
To
useEffect(() => { ...}, []);
Classic React 😅 Thanks for the updates, @Gaztoof.
Glad you're unblocked! 🎉
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
DataStore
Amplify Version
v6
Amplify Categories
api
Backend
Amplify CLI
Environment information
Describe the bug
When calling DataStore.Save more than once in a single function, only the first DataStore.Save actually works. If you repeat the a DataStore.Save call 3 times, only the first will be registered.
Expected behavior
I expect all of the DataStore.Save calls to work
Reproduction steps
Code Snippet
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
Pixel 8
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
{ "name": "consultu", "main": "expo-router/entry", "version": "1.0.0", "scripts": { "start": "expo start", "reset-project": "node ./scripts/reset-project.js", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web", "test": "jest --watchAll", "lint": "expo lint" }, "jest": { "preset": "jest-expo" }, "dependencies": { "@aws-amplify/react-native": "^1.1.4", "@aws-amplify/ui-react": "^6.1.14", "@aws-amplify/ui-react-native": "^2.2.3", "@expo/vector-icons": "^14.0.2", "@react-native-async-storage/async-storage": "^1.24.0", "@react-native-community/datetimepicker": "git+https://github.com/react-native-datetimepicker/datetimepicker.git", "@react-native-community/netinfo": "^11.3.2", "@react-navigation/material-top-tabs": "^6.6.14", "@react-navigation/native": "^6.1.18", "@react-navigation/stack": "^6.4.1", "aws-amplify": "^6.4.3", "aws-amplify-react-native": "^7.0.8", "expo": "^51.0.21", "expo-constants": "~16.0.2", "expo-font": "~12.0.9", "expo-image-picker": "~15.0.7", "expo-linear-gradient": "~13.0.2", "expo-linking": "~6.3.1", "expo-router": "~3.5.18", "expo-splash-screen": "~0.27.5", "expo-status-bar": "~1.12.1", "expo-system-ui": "~3.0.7", "expo-web-browser": "~13.0.3", "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.74.3", "react-native-country-picker-modal": "^2.0.0", "react-native-elements": "^3.4.3", "react-native-gesture-handler": "~2.16.1", "react-native-get-random-values": "^1.11.0", "react-native-google-address-validation": "^1.2.7", "react-native-iconly": "^1.0.12", "react-native-linear-gradient": "^2.8.3", "react-native-modal-datetime-picker": "^17.1.0", "react-native-pager-view": "6.3.0", "react-native-reanimated": "~3.10.1", "react-native-safe-area-context": "^4.10.8", "react-native-screens": "3.31.1", "react-native-svg": "^15.4.0", "react-native-tab-view": "^3.5.2", "react-native-tag-input": "^0.0.21", "react-native-tags-input": "^1.0.10", "react-native-url-polyfill": "^2.0.0", "react-native-vector-icons": "^10.1.0", "react-native-web": "~0.19.10", "react-navigation-stack": "^2.10.4", "react-phone-number-input": "^3.4.5" }, "devDependencies": { "@aws-amplify/backend": "^1.0.4", "@aws-amplify/backend-cli": "^1.2.1", "@babel/core": "^7.20.0", "@types/jest": "^29.5.12", "@types/react": "~18.2.45", "@types/react-test-renderer": "^18.0.7", "aws-cdk": "^2.150.0", "aws-cdk-lib": "^2.150.0", "constructs": "^10.3.0", "esbuild": "^0.23.0", "jest": "^29.2.1", "jest-expo": "~51.0.3", "react-test-renderer": "18.2.0", "tsx": "^4.16.3", "typescript": "^5.5.4" }, "private": true }