Listing all the blog posts with real-time updates with React Native and Expo
In this section, we will learn how to add a real-time subscription to the app, which is important if you are creating an app where you want to let users subscribe to any updates that they are interested in, such as receiving a notification about a blog post or a new article for a website or app. Let's get started:
- Open the
App.tsx
file again and add the following code anywhere within the mainApp
function code block:Â Â const createSubscription: any = API.graphql( Â Â Â Â graphqlOperation(subscriptions.onCreatePost) Â Â ); Â Â createSubscription.subscribe({ Â Â Â Â next: (postData: any) => { Â Â Â Â Â Â console.log("onCreatePost", postData); Â Â Â Â Â Â fetchPosts(); Â Â Â Â }, Â Â }); Â Â const updateSubscription: any = API.graphql( Â Â ...