6

Now I am using firebase JS SDK to use phone authentication. I followed the web method.

Here is my code:

  handleClick = () => {
    this.state.verify_otp = "flex";
    this.state.register = "none";
    this.recaptcha = new firebase.auth.RecaptchaVerifier("recaptcha1");
    this.number = this.state.phone;
  };

.

<View
    style={{
        alignItems: "center",
        justifyContent: "center",
        flex: 1,
        display: this.state.captcha,
    }}
>
    <div>
        <div id="recaptcha1"></div>
    </div>
</View>

Is it possible to use a tag in react-native code?

Stu Furlong
  • 3,490
  • 5
  • 34
  • 47
SatelBill
  • 641
  • 2
  • 12
  • 28

5 Answers5

3

No, not natively. React Native doesn't support direct HTML, as it is not a web framework.

For rendering HTML in React Native, see Render HTML in React Native

ΔO 'delta zero'
  • 3,506
  • 1
  • 19
  • 31
1

No, it's not possible to use html tags in react-native

edit: list of basic RN components https://reactnative.dev/docs/components-and-apis#basic-components

Hyetigran
  • 1,150
  • 3
  • 11
  • 29
1

No, you cannot use the <div> element inside a react native component because React Native does not have a DOM.

Octamassss
  • 11
  • 1
1

Unfortunately its not possible. Div is an HTML element which can be read by Browser. For mobile app, Its View

However you can build your own div

class Div extends Component {  //or Class Span extends Component

  static propTypes = {
      style : PropTypes.obj
      onClick : PropTypes.func   // ...
  }

  render (){
        return (
        <View>
        
    /* whatever is needed to pass everything through  ... */
  
       </View>
 )    }

}

Arnab
  • 936
  • 7
  • 13
1

You could use react-native-render-html to achieve like follow. (if couldn't work have to install react-native-webview)

import * as React from 'react';
import { Text, View, StyleSheet,ScrollView, Dimensions } from 'react-native';
import Constants from 'expo-constants';
import HTML from 'react-native-render-html';


const htmlContent = `
    <h1>This HTML snippet is Using react-native-render-html !</h1>
    <h2>Trying many tag to render html</h2>
    <img src="https://i.imgur.com/fJ71V9b.jpg" />
    <div>Here is what you want to add!!!!!<div>`
    ;
export default function App() {
  return (
    <View style={styles.container}>
     <ScrollView style={{ flex: 1 }}>
            <HTML html={htmlContent} imagesMaxWidth={Dimensions.get('window').width} />
      </ScrollView>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
  } 
});

Code example on snack

高鵬翔
  • 1,997
  • 2
  • 8
  • 21