JavaScript How to write if condition with two statement in React Native write condition in excel,write condition in sql,write condition

I am just confused about how to match two statement like if else of JavaScript in React Native

for e.g.,

if(array.length != null && array.length >= 2){
    alert("Array Is Greater Than 2")
}else if(array.length != null ){
    alert("Array Is Less Than 2")
}else{
    alert("Array is null")
}

I know how to pass signle condition in React Native like

for e.g.,

{
    array.length != null &&
    <View>
        /* Content Here */
    </View>
}

or

{
    array.length != null ?
    <View>
        /* If Content Here */
    </View>
    :
    <View>
        /* Else Content Here */
    </View>
}

But How do I create if state like first one ?

Answer:1

You can have nested ternary conditions, but i will not suggest that because it will be not that readable. Other option is you can put all those conditions inside a function and call that function from render method.

Like this:

renderElement () {
    if(array.length != null && array.length >= 2){
        alert("Array Is Greater Than 2");
        return <p>If condition</p>;
    }else if(array.length != null ){
        alert("Array Is Less Than 2");
        return <p>If-Else condition</p>;
    }else{
        alert("Array is null");
        return <p>Else condition</p>;
    }
}

render () {
    const element = this.renderElement();
    // now you can use element to render that element at any place
}

Nested ternary conditions:

{
    array.length != null && array.length >= 2 ?
        <View>
            /* Array Is Greater Than 2 */
        </View>
    :
        array.length != null?
            <View>
                /* Array Is Less Than 2 */
            </View>
        :
            <View>
                /* Array Is Null */
            </View>
}
Answer:2

I'm trying to have a page that switches out which component is rendered based off of a pair of navigation buttons. The page is set up like this ReactDOM.render(<Logo/>, document.getElementById(...

I'm trying to have a page that switches out which component is rendered based off of a pair of navigation buttons. The page is set up like this ReactDOM.render(<Logo/>, document.getElementById(...

  1. programmatically change route react
  2. programmatically change route react router
  3. react programmatically change style
  4. react programmatically change props

I am new to ReactJS. I am stuck in one problem. I get textbox value from calling API which has predefined value. but When I try to edit its value then it is not letting me to edit. class ...

I am new to ReactJS. I am stuck in one problem. I get textbox value from calling API which has predefined value. but When I try to edit its value then it is not letting me to edit. class ...

I want to change image and that trigger an image update. This is for example http://jsbin.com/kuluyike/3/edit?html,js,output <div id="colorPicker"> <img v-attr="src:color" alt="{{...

I want to change image and that trigger an image update. This is for example http://jsbin.com/kuluyike/3/edit?html,js,output <div id="colorPicker"> <img v-attr="src:color" alt="{{...

  1. jquery when radio selected
  2. when radio button selected
  3. when radio button is selected jquery
  4. when radio button is selected javascript

I have multiple sliders which is defined by document.querySelectorAll( '.js-slider' ); on tooltips.format I would like to insert a label above the value, which is defined on the current slide object ...

I have multiple sliders which is defined by document.querySelectorAll( '.js-slider' ); on tooltips.format I would like to insert a label above the value, which is defined on the current slide object ...