Hello Friends 👋,

Welcome To Infinitbility! ❤️

This tutorial helps you to empty string in react native function, and render the component. here you will get an example check an empty string in functions, render components or also handle if the string contains space.

To handle empty string in function we use Javascript Truthy Values ( https://developer.mozilla.org/en-US/docs/Glossary/Truthy ) syntax and for in render we use JSX syntax to handle empty string.

Check empty string in react native functions

In React Native function, we are able to write simply if… else statement to handle or check empty string.

checkEmpty = () => {

    let emptyString = "";
    if(!emptyString){
        // Your code goes here
    }
}

Check empty string in react native render

In React Native render, we use JSX syntax to check string is empty or not.

render(){
    let emptyString = "";
    return(
        <View>
        {!emptyString ? (<Text>{"Empty String"}</Text>) : (<Text>{"Not Empty String"}</Text>)}
        </View>
    )
}

Handle space when checking empty string in react native

Above String return if the string has space, when you handle space then Javascript provide trim() function to remove the left and right side space in string.

!emptyString.trim();

Thanks for reading…