Navigate back to the homepage

How to check empty string in react native

Infinitbility
React Native
September 2nd, 2021 · 1 min read
How to check empty string in react native

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.

1checkEmpty = () => {
2
3 let emptyString = "";
4 if(!emptyString){
5 // Your code goes here
6 }
7}

Check empty string in react native render

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

1render(){
2 let emptyString = "";
3 return(
4 <View>
5 {!emptyString ? (<Text>{"Empty String"}</Text>) : (<Text>{"Not Empty String"}</Text>)}
6 </View>
7 )
8}

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.

1!emptyString.trim();

Thanks for reading…

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.

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]

Tutorials

React Native

Categories

More articles from Infinitbility

How to access env variable in laravel

How to access env variable in laravel

Use env variable in laravel controller and blade example

September 1st, 2021 · 1 min read
How to enable and disable debug mode in laravel

How to enable and disable debug mode in laravel

Enable and disable debug mode in laravel example

August 31st, 2021 · 1 min read
© 2020–2021 Infinitbility
About
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]