undefinedfix
Sign in

react.js What is the meaning of the code of steps component in?

Alassane edited in Sun, 13 Mar 2022

react.js What is the meaning of the code of steps component in?

<Steps progressDot current={state ? state[0] ? state[0] : null : null}
          status={this.checkStatus(state ? state[1] ? state[1] : null : null)}>
       ......   
</Steps>
4 Replies
drummingdemon
commented on Sun, 13 Mar 2022

That's what I mean

state && state[0] ? state[0] : null
Nahuel
commented on Sun, 13 Mar 2022

Equivalent to: state? (state [0]? State [0]: null): nullmdn has a good explanation. The important point is that although the conditional operator is right associative, it is evaluated from left to right

ZTEP
commented on Sun, 13 Mar 2022

Ternary controller to prevent null value. For example, data = [], is it not undefined to take data [0] directly

Posemto
commented on Sun, 13 Mar 2022
if (state){
    if (state[0]){
        return state[0]
    } else {
        return null
    }
} else {
    return null
}
lock This question has been locked and the reply function has been disabled.