Share Tweet and URL From React Native App to Twitter

Hello friends, In today’s tutorial we would learn about sharing message(tweet) directly from react native application to Twitter. This can be possible via Linking component of react native. Now what we actually do in this tutorial is use twitter’s own URL ‘https://twitter.com/intent/tweet + Params’ to open the Twitter in mobile. If Twitter app is installed in our mobile then it will open Twitter app and If we don’t have the App then it will open the default browser of mobile. So in this tutorial we would Share Tweet and URL From React Native App to Twitter.

Contents in this project Share Tweet and URL From React Native App to Twitter :-

1. Open your project’s main App.js file and import useState, Alert, Linking, StyleSheet, View, Text, TouchableOpacity, TextInput and Platform component.

2. Creating our main App component.

3. Creating a State named as shareURL_Twitter with State update method setShareURL_Twitter. In this state we would store the HTTP URL.

4. Creating another state named as tweet with state update method setTweet. In this state we would store the Tweet we would share on Twitter.

5. Creating another State named as tweetAccount with State update method setTweetAccount. In this state we would store the Account from which we want to share Tweet.

6. Creating a function named as postTweet(). In this method we would simply add all above 3 States with Twitter share URL.

7. Creating return() block, Now we would make 3 Text Input component with a Button to share Tweet.

8. Creating Style.

9. Complete Source Code for App.js file :-

Screenshots :-

Leave a Reply

Your email address will not be published.