'Sharing data to social media in React native
I have an app in which i want to share specific data to social media like facebook,twitter,pinterest etc once the user clicks on the social icon. I have already used react native link which sends me to the pages of these platforms. But i want to share data to these once clicked. I have done this for whatsapp which is like this:
<TouchableOpacity onPress={() => {
let url = 'whatsapp://send?text=${hello}&phone=${01753362960}';
Linking.openURL(url).then((data) => {
console.log('open whatsapp', data)
}).catch(() => {
console.log('App not installed')
});
}} >
<Icon name='logo-whatsapp' style={{color: '#395894', fontSize: 30, marginRight: 10}}/>
</TouchableOpacity>
let url = 'twitter://send?text=hello this is checked'
How can i do this for other social media platforms?
Solution 1:[1]
For twitter please use this,
let url = 'twitter://post?message=${yourMsg}'
Solution 2:[2]
I would do it this way: https://facebook.github.io/react-native/docs/share
This way the user can chose what app he wants to share to based on apps installed on users device
Solution 3:[3]
react-native-share is a good package to use for making some stuff share at different platforms. Back in early 2019 this package wasn't this much mature, but now it's really usefull.
https://github.com/react-native-community/react-native-share
Have a look at here. Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ritviz Sharma |
| Solution 2 | Nino9612 |
| Solution 3 | Soban Arshad |
