Sunday, February 3, 2019

Sharing to WhatsApp from a react native application

This tutorial explains how to share particular message to whatsapp application in react native application. Sharing a content in whataspp application is very easy and simple. Just you need to import Linking class from the react-native package.

Sharing to WhatsApp from a react native application

Follow the below steps to share text content in whatsapp application :

1. import Linking class from the react-native package.
import { Linking } from "react-native";

2. Call the below function, in order to share content in whatsapp application.
shareToWhatsApp = (text) => {
  Linking.openURL(`whatsapp://send?text=${text}`);
}

Lets try the below function in your react native application, that helps to share content in whatsapp application.

Share a message

Lets use below function in react native to share message in whatsapp application.

shareToWhatsApp = (text) => {
 Linking.openURL(`whatsapp://send?text=${text}`);
}

Share a message with specific contact

Lets use below function in react native to share message to particular user in whatsapp application.

shareToWhatsAppWithContact = (text, phoneNumber) => {
 Linking.openURL(`whatsapp://send?text=${text}&phone=${phoneNumber}`);
}

This is all about Sharing to WhatsApp from a react native application.Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.

1 comment: