Opening external links with Linking in React Native
In this post we will give you information about Opening external links with Linking in React Native. Hear we will give you detail about Opening external links with Linking in React NativeAnd how to use it also give you demo for it if it is necessary.
In this tutorial, we’ll see how to use Linking
in React Native to open external links and URLs using the default web browser in your mobile system.
After implementing the functionality of the read later method using AsyncStorage
, let’s now see how to use the Linking
module in React Native to open a URL using the web browser.
Let’s start by importing Linking
in the App.js
file as follows:
import { Linking} from 'react-native';
Next, add the following method:
const openURL = (url) => { Linking.openURL(url).catch((err) => console.error('An error occurred', err));}
This method calls the openURL()
method of Linking
to open a URL in the web browser.
Finally, you need to call this method in the ArticleItem
component as follows:
const ArticleItem = ({article}) => { const { title, description, url, urlToImage } = article; return ( <View style = { styles.articleContainer }> <Image style={ styles.articleImage } source= /> <Text style= { styles.articleTitle }> { title } </Text> <Text style = { styles.articleDescription }> { description } </Text> <View style = { styles.articleBtns}> <IconButton width= "50%" color = "white" bgcolor = "#ff5c5c" icon = { readIcon } onPress = { () => { console.log("Button pressed!")} } title = "Open" /> <IconButton width= "50%" color = "white" bgcolor = "#ff5c5c" icon = { bookmarkIcon } onPress = { () => { saveArticle(title, url); } } title = "Read later" /> </View> </View> )}
When you click on the Open button, the corresponding article will be opened in the default web browser in the mobile system.
You can do more things with Linking
with provides you with a general interface to interact with both incoming and outgoing app links. You can refer to the docs for more information.
Hope this code and post will helped you for implement Opening external links with Linking in React Native. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs