if else condition inside react native return

Solutions on MaxInterview for if else condition inside react native return by the best coders in the world

showing results for - "if else condition inside react native return"
Emilie
30 Feb 2019
1If you want to render the element conditionally then use ternary operator, like
2this:
3
4render() {
5    return (   
6        <View style={styles.container}>
7            {this.state.value == 'news'? <Text>data</Text>: null }
8        </View>
9    )
10}
11
12Another option is, call a function from jsx and put all the if-else logic inside
13that, like this:
14
15renderElement(){
16   if(this.state.value == 'news')
17      return <Text>data</Text>;
18   return null;
19}
20
21render() {
22    return (   
23        <View style={styles.container}>
24            { this.renderElement() }
25        </View>
26    )
27}
28
29If you want to render the element conditionally then use ternary operator, like 
30this:
31
32render() {
33    return (   
34        <View style={styles.container}>
35            {this.state.value == 'news'? <Text>data</Text>: null }
36        </View>
37    )
38}
39Another option is, call a function from jsx and put all the if-else logic 
40inside that, like this:
41
42renderElement(){
43   if(this.state.value == 'news')
44      return <Text>data</Text>;
45   return null;
46}
47
48render() {
49    return (   
50        <View style={styles.container}>
51            { this.renderElement() }
52        </View>
53    )
54}
Leona
22 Aug 2018
1renderConditionalText() {
2    if (this.state.isSignUp) {
3        return <Text> Sign Up </Text>;
4    }
5     return <Text> Forgot Password </Text>; 
6}
7
queries leading to this page
how to make a if statment in react nativeif else in view container react nativereactnative if else in returnreact native if stament andif else in css in react nativereact native jsx if elseif in react native renderhow to add an if statement in recat nativehow to do an if block in react nativeif jsx react nativeif inside return react nativeif condition inside return react nativehow to write if else condition inside the return statement react nativereact native if else jsxelse if in react native 222020 22if statement react nativeif elseif statement in react nativeif else statment inside text react nativeif statement inside text react nativeif else and return string in text react native 22react native 22 if else in renderif else in react native return statementhow to use if else condition in react nativeview statement inside if condition in react nativereact native if stament with andreact native if else renderusing if else in react nativehow to apply if else in a return react nativeif condition for text in react nativehow to apply if else in a view react nativereact native how to write if statement inside the return viewif else statement react nativehow to use if statement in 3ctext 3e react nativeif condition in react native textif statement on whether to include a react native componentelseif in react nativesimple if else condition app react nativereact native if statement for stylehow to write if inside jsx in react nativeif condition in render method react nativehow to but a if statement in react nativeif statement in view react nativereact native if in renderreact native if else condition in viewreact native if elsereact native if else in renderif else return reacthow to render a component based on an if statement ract antiv eif inside react native componentreact native styles if elseif else condition inside react native returnreact native if statementif condition inside render in react nativeif condition in view react nativereact native if condition in viewif and else statement in react native viewif else in return react nativeif statemena in react nativeif else react nativereact native render if statementreact native if if condition in react nativereact native if else in returnif else render react nativehow to pass an if else statement react nativehow to do an if statement in react nativehow to use if condition in react native text componentreact native if condition in renderif else inside view react nativeif 26 26 condition in react nativeif else inside component react nativecomoment if react nativeif else statement inside react functionif statement in style react nativeif condition in react native renderif condition react nativehow to apply the if condition in reactnativehow to use if else inside render in react nativeelse if react nativereact native if condition in view with how to if in react nativereact native if andhow to use if condition in react native textcan i have an if else statement in a view react nativehowto write else condition in react native viewwhy cant i write if else in react nativereact native if statemtnt sif statement in frontend code react nativehow to use if else condition in react native return if else in react native jsxif else inside render react jsreact native if else in stylehow to insert if condition in react nativehow to put an if statement in react nativereact native else ifif else in text react nativehow to write if statement in react native returnif condition inside render react nativeusing if inside the view in react nativereact native if condition in stylerect native ifreact native 21 3d if statementelse if in react nativeif else statement inside text react nativereact native if else statementhow to use if condition inside view in react nativeif statement in react nativereact native if conditionif else im return react nativeif and else in react nativeif in react nativereact native stye ifif else condition in react native viewreact native if stateif else condition use in return react native viewif condition in react native viewif else in react native jsx componentsreact native if else ifif else if inside view reactr nativehow to write an if statement in react native 3fif else in react nativehow to do if statement in react nativereact native if stament react native if statement in viewinline if statrmrnt react nativehow many if statement can be used in condition in react nativeif else in react native viewhow to use if else in react nativeif else statement in react nativereact native if condition in returnreact native ifreact native use if statement in returnif statement function component react nativereact native if else if js 6react native if statement in returnif else in view react nativeif else if react nativeif else in return view react nativehow to do if in return in react nativereact native if else in viewif else inside react render functionif statements in react nativeand or in if elase react nativeinsert if else in return react nativeif else 3 condition react nativeif else condition inside react native return