AWS introduced Amplify DataStore at re:invent 2019. Datastore is a persistent on-device storage repository for developers to write, read, and observe changes to data.
According to the announcement does Amplify DataStore allows developers to write apps leveraging distributed data without writing additional code for offline or online scenario. Amplify DataStore can be used as a stand-alone local datastore in web and mobile applications, with no connection to the cloud, or the need to have an AWS Account. Under the hood is the datastore connected to app sync graphQl API. Awesome feature is the easy use and offline capability. See also announcement https://aws.amazon.com/de/blogs/aws/amplify-datastore-simplify-development-of-offline-apps-with-graphql/ or doc https://aws-amplify.github.io/docs/js/datastore.
However, amplify supports popular web frameworks, such as Angular, React, and Vue. It also supports mobile applications developed with React Native, Swift for iOS, or Java for Android.
After announcement i was motivated to use the feature based on a react native app and expo.
But getting error "Node is not supported" using aws amplify datastore on react native and expo.
[Unhandled promise rejection: Error: Node is not supported]
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:63717:20 in getDefaultAdapter
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:63730:47 in Storage
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:64010:31 in ExclusiveStorage
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:61426:81 in <unknown>
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60761:23 in step
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60663:9 in <unknown>
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
- node_modules/promise/setimmediate/core.js:200:23 in doResolve
- node_modules/promise/setimmediate/core.js:66:12 in Promise
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60642:34 in <unknown>
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:61204:17 in <unknown>
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60761:23 in step
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60663:9 in <unknown>
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
- node_modules/promise/setimmediate/core.js:200:23 in doResolve
- node_modules/promise/setimmediate/core.js:66:12 in Promise
- node_modules/@aws-amplify/datastore/dist/aws-amplify-datastore.js:60642:34 in <unknown>
* App.js:43:40 in loadData$
Imported Datastore and model:
import { DataStore } from "@aws-amplify/datastore";
import { Post } from "./src/models";
import amplify from './aws-exports';
Amplify.configure(amplify);
And create an load data using datastore API:
async loadData() {
await DataStore.save(
new Post({
name: `My First Post`
})
).catch(err => {
console.error(err)
});
const posts = await DataStore.query(Post);
console.log(posts)
}
Dependencies:
"dependencies": {
"@aws-amplify/api": "^2.1.1",
"@aws-amplify/core": "^2.2.0",
"@aws-amplify/datastore": "^1.0.2",
"@aws-amplify/pubsub": "^2.1.1",
"aws-amplify": "1.2.2",
"expo": "^35.0.0",
"react": "16.8.3",
"react-dom": "16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
"react-native-web": "^0.11.7"
}
The library is not yet ready for React Native, at this time ref: https://github.com/aws-amplify/amplify-js/issues/4527
DataStore is now supported on React Native. You can find installation instructions here: https://aws-amplify.github.io/docs/js/datastore#for-react-native
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With