Navigate back to the homepage

how to check null value in react native?

Infinitbility
React Native
September 8th, 2022 · 1 min read

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To check null value in react native, use if statement it will handle all falsy value or you can compare with null it self.

Let’s see short example to use if statement to handle null value.

1let value = null;
2if(value){
3 console.log("value have data")
4} else {
5 console.log("value is null or falsy value")
6}

Today, I’m going to show you How do I check null value in react native, as above mentioned, I’m going to use the above-mentioned use if statement.

Let’s start today’s tutorial how do you check null value in react native?

React native check null value example using if

Here, we will take example of string, number, boolean, object and undefined datatype.

1import React, { useState, useEffect } from "react";
2import { Text, View } from 'react-native';
3export default function App() {
4 const [value, setValue] = useState(null);
5
6 useEffect(() => {
7 if(value){
8 console.log("value have data")
9 } else {
10 console.log("value is null or falsy value")
11 }
12 }, []);
13
14 return (
15 <View>
16 <Text>{value ? "value have data" : "value is null or falsy value"}</Text>
17 </View>
18 );
19}

Output

React native check null value example compare with null

Here, we will compare value with null and also handle if value have null as string.

1import React, { useState, useEffect } from "react";
2import { Text, View } from 'react-native';
3export default function App() {
4 const [value, setValue] = useState(null);
5
6 useEffect(() => {
7 if(value == null || value == "null"){
8 console.log("value is null")
9 } else {
10 console.log("value have data")
11 }
12 }, []);
13
14 return (
15 <View>
16 <Text>{(value == null || value == "null") ? "value is null" : "value have data"}</Text>
17 </View>
18 );
19}

Output

I hope it helps you, All the best 👍.

Follow me on Twitter

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]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to check blank space in typescript?

An example of check blank space in typeScript with the step-by-step guide.

September 7th, 2022 · 1 min read

how to check blank value in typescript?

An example of check blank value in typeScript with the step-by-step guide.

September 7th, 2022 · 1 min read
© 2020–2022 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]