← Back to Chapters

React Native Share API

? React Native Share API

? Quick Overview

The Share API in React Native allows apps to open the native sharing dialog so users can share text, links, or other content using installed apps like WhatsApp, Email, or SMS.

? Key Concepts

  • Uses the built-in Share module from React Native
  • Works on both Android and iOS
  • Triggers native OS share sheet
  • Supports text, URLs, and titles

? Syntax / Theory

The Share API exposes a single main method called Share.share(). It accepts an object containing data to be shared and returns a Promise with the result.

? View Code Example
// Import Share module from react-native
import { Share } from "react-native";

// Function to trigger share dialog
Share.share({
message: "Hello from React Native!",
url: "https://reactnative.dev",
title: "React Native"
});

? Code Example(s)

? View Code Example
// Complete example using a button
import React from "react";
import { View, Button, Share } from "react-native";

export default function App() {

const onShare = async () => {
try {
await Share.share({
message: "Check out React Native Share API"
});
} catch (error) {
console.log(error.message);
}
};

return (
<View>
<Button title="Share" onPress={onShare} />
</View>
);
}

? Live Output / Explanation

What Happens?

When the Share button is pressed, the native share dialog opens, allowing the user to select an app to share the message.

? Interactive / Visual Explanation

Since we can't run actual React Native code here in the browser, below is a Simulation of how the Native Share Sheet behaves. Use the phone mockup below to understand the flow.

My App

Article: "Learning React Native"
Tap share to test

> App Mounted
> Waiting for user interaction...

? Use Cases

  • Sharing app links
  • Sharing text content
  • Referral features
  • Sharing blog posts or media links

? Tips & Best Practices

  • Always wrap Share calls in try/catch
  • Test on both Android and iOS
  • Keep shared messages short and clear

? Try It Yourself

  • Share dynamic text from state
  • Share a URL only
  • Customize share title