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( ...