Navigate back to the homepage

how to open any link from react native render Html

Infinitbility
React Native
February 26th, 2021 · 1 min read
how to open any link from react native render Html

Hello Friends 👋,

Welcome To Infinitbility! ❤️

React native render HTML provides the feature to render anchor tag or link in your HTML content but you want the link is clickable then you have to some extra stuff.

We know when we want to open any link from react native app we use react native linking to redirect the app to the browser and open the URL.

So, we have to do the same thing here also for open URLs or you want to click on the link.

Follow the below steps to make your HTML link clickable.

React native render HTML provides props onLinkPress to handle link.

Add these props to your HTML component

1<HTML
2 ...
3 onLinkPress={(evt, href) => { console.log(href) }}
4 ...
5/>

Step 2: use linking with render HTML

  • import linking from react native
1import { Linking } from 'react-native';
1<HTML
2 ...
3 onLinkPress={(evt, href) => { Linking.openURL(href) }}
4 ...
5/>
1import React, { Component } from "react";
2import { ScrollView, useWindowDimensions, Linking } from "react-native";
3import HTML from "react-native-render-html";
4
5const htmlContent = `
6 <h1>This HTML snippet is now rendered with native components !</h1>
7 <h2>Enjoy a webview-free and blazing fast application</h2>
8 <a href="https://infinitbility.com" >infinitbility.com</h2>
9 <img src="https://i.imgur.com/dHLmxfO.jpg?2" />
10 <em style="textAlign: center;">Look at how happy this native cat is</em>
11`;
12
13export default function Demo() {
14 const contentWidth = useWindowDimensions().width;
15 return (
16 <ScrollView style={{ flex: 1 }}>
17 <HTML
18 source={{ html: htmlContent }}
19 contentWidth={contentWidth}
20 onLinkPress={(evt, href) => { Linking.openURL(href) }}
21 />
22 </ScrollView>
23 );
24}

Thanks for reading …

More From React Native Tutorial

Basics

  1. Introduction To React Native
  2. React Native Environment Setup using expo
  3. React Native Environment Setup for windows
  4. React Native Environment setup on Mac OS
  5. React Native Environment setup on linux
  6. React Native Project Structure
  7. React Native State
  8. React Native Props
  9. React Native Styling
  10. React Native Flexbox
  11. React Native Text
  12. React Native Textinput
  13. React Native Commands
  14. React Native ScrollView

Advances

  1. React Native Dark Mode
  2. React Native Fonts
  3. React Native SQLite
  4. React Native DatepickerAndroid
  5. React native ScrollView scroll to position
  6. How to align icon with text in react native
  7. React Native Image
  8. React Native Firebase Crashlytics
  9. React Native Async Storage
  10. React Native Share

Error & Issue Solution

  1. Task :app:transformDexArchiveWithDexMergerForDebug FAILED In React Native
  2. Expiring Daemon because JVM heap space is exhausted In React Native
  3. Task :app:transformNativeLibsWithMergeJniLibsForDebug FAILED In React Native
  4. Unable to determine the current character, it is not a string, number, array, or object in react native
  5. App crashed immediately after install react native video or track player
  6. how to delete SQLite database in android react native
  7. React native material dropdown twice click issue
  8. How to get the current route in react-navigation?
  9. how to disable drawer on the drawer navigation screen?
  10. Image not showing in ios 14 react native
  11. React Native image picker launchimagelibrary on second time issue
  12. how to open any link from react native render Html
  13. Network request failed in react native fetch
  14. React Native upload video example

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

More articles from Infinitbility

React Native image picker launchimagelibrary on second time issue

React Native image picker launchimagelibrary on second time issue

React Native image picker launchimagelibrary doesn't open image gallery when click second time.

February 22nd, 2021 · 1 min read
Laravel Clear cache, config, view and Routes

Laravel Clear cache, config, view and Routes

Laravel Clear cache, config, view and Routes using artisan cammand with example.

February 6th, 2021 · 2 min read
© 2020–2021 Infinitbility
Disclaimer
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]