How to Convert Boolean to String in React Native?

Sep 21, 2022 . Admin

Today, I would like to show you convert boolean to string in react native. I would like to share with you boolean to string in react native example. This article goes in detailed on boolean to string in react native. you will learn react native boolean to string example. Follow bellow tutorial step of how to convert boolean to string in react native.

In this example,We will learn to boolean to string in react native.you can use tostring to check value for string or not in rect native.below's this example

Step 1: Download Project

In the first step run the following command to create a project.

expo init ExampleApp
Step 2: App.js

In this step, You will open the App.js file and put the code.

import React, { useState, useEffect } from 'react';
import { Text, View, StyleSheet } from 'react-native';

export default function App() {

  const [str, setStr] = useState("");

  useEffect(() => {
    let strBool = true;
    let result = strBool.toString();
    console.log(result);
    setStr(result);
  }, []);

  return (
    <View style={styles.container}>
        <Text>{str} - {typeof str}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
});
Step 3: Run Project

In the last step run your project using the below command.

expo start

You can QR code scan in Expo Go Application on mobile.

Output:

It will help you...

#React Native