Reading time: < 1 minute
Today, I’m going to show you how to add the share function to an app using the Share feature included in React Native.
The first thing we need to do is import the library:
import { Share } from "react-native";
Next, we add the share function to the render of our screen or component.
const shareData = async (customOptions) => { try { await Share.share(customOptions); } catch (error) { alert(error.message); } };
Now, we add the share action to the component or button.
onPress={async () => { await shareData({ title: "Share", message: "Shared text/content", url: "www.url.com", }); }}
You can include different options. For more information, check out https://reactnative.dev/docs/share