Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
react-native-share
Advanced tools
The react-native-share package allows you to share content such as text, images, and files from your React Native app to other apps on the user's device. It supports both Android and iOS platforms.
Share Text
This feature allows you to share plain text messages. The code sample demonstrates how to share a simple text message using the react-native-share package.
import Share from 'react-native-share';
const shareText = async () => {
const shareOptions = {
message: 'Hello, this is a text message!',
};
try {
await Share.open(shareOptions);
} catch (error) {
console.log('Error =>', error);
}
};
Share Image
This feature allows you to share images. The code sample demonstrates how to share an image using a base64 encoded string.
import Share from 'react-native-share';
const shareImage = async () => {
const shareOptions = {
url: 'data:image/png;base64,<base64_encoded_image>',
};
try {
await Share.open(shareOptions);
} catch (error) {
console.log('Error =>', error);
}
};
Share File
This feature allows you to share files. The code sample demonstrates how to share a file from a given file path.
import Share from 'react-native-share';
const shareFile = async () => {
const shareOptions = {
url: 'file://path/to/your/file.pdf',
};
try {
await Share.open(shareOptions);
} catch (error) {
console.log('Error =>', error);
}
};
Share with Social Media
This feature allows you to share content directly to specific social media apps. The code sample demonstrates how to share a message directly to WhatsApp.
import Share from 'react-native-share';
const shareToWhatsApp = async () => {
const shareOptions = {
message: 'Hello, sharing this via WhatsApp!',
social: Share.Social.WHATSAPP,
};
try {
await Share.shareSingle(shareOptions);
} catch (error) {
console.log('Error =>', error);
}
};
The react-native-social-share package allows you to share content to social media platforms like Facebook, Twitter, and WhatsApp. It is more focused on social media sharing compared to react-native-share, which offers a broader range of sharing options.
The react-native-share-menu package allows your app to receive content shared from other apps. While react-native-share focuses on sharing content from your app, react-native-share-menu is designed to handle incoming shared content.
The expo-sharing package is part of the Expo ecosystem and allows you to share files with other apps. It is simpler to use within Expo-managed projects but may not offer as many customization options as react-native-share.
React Native Share, is a simple tool for sharing messages and files with other apps.
If you are using react-native >= 0.7X
and/or the new arch you just need to do a simple:
yarn add react-native-share
Or if are using npm:
npm i react-native-share --save
After that, we need to install the dependencies to use the project on iOS(you can skip this part if you are using this on Android).
Now run a simple: npx pod-install
or cd ios && pod install
. After that, you should be able to use the library on both Platforms, iOS and Android.
Then simply import:
import Share from 'react-native-share';
Share.open(options)
.then((res) => {
console.log(res);
})
.catch((err) => {
err && console.log(err);
});
Which you do something similar to this:
If you are using a older version of react-native
or react-native-share
, having any problem or want to know how use Share.open
and other functions, please refer to our new docs and help us improve that.🚀
FAQs
Social share, sending simple data to other apps.
The npm package react-native-share receives a total of 240,297 weekly downloads. As such, react-native-share popularity was classified as popular.
We found that react-native-share demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.