If Else Condition Inside React Native JSX Return Functional

Hello friends, From now on we’re concentrating on basic questions of React Native JSX. So in today’s tutorial we would learn about how we can use If Else conditional statement inside return block in functional component. But here comes the rabbit from the hole, Functional component JSX syntax does not support directly If-Else conditions inside return() block. If we want to use If-Else then we have to make a custom component outside the return block then put our condition inside it. So in this tutorial we would learn about If Else Condition Inside React Native JSX Return Functional Component.

Contents in this project If Else Condition Inside React Native JSX Return Functional Component :

1. Open your project’s main App.js file and import useState, View, StyleSheet, Text, Button and SafeAreaView component.

2. Creating our main App component.

3. Creating 1 State named as text with State update method setText. We would use this State to True and False the If-Else condition.

4. Creating a Component named as renderText(). In this component we would put the IF-Else conditional Statement and show different text on true and false condition.

5. Creating return() block, Here we would call our renderText component. Now we would make 2 Buttons. On each button we would set state value to True and False and this will directly impact to or condition.

6. Creating Style.

7. Complete Source Code for App.js file :-

Screenshots :-

If Else Condition Inside React Native JSX Return Functional