Home > Software design >  Conditional (ternary) operator is going directly to else option
Conditional (ternary) operator is going directly to else option

Time:03-14

I am trying to make a conditional to choose a link according to the type of user I get from the sessionStorage, but it always goes directly to else. I can't find the error, and I don't know what else to try.

I´m using React, and the function Link is what I'm using as href for the

Thank you very much!

export default function IndexCards(props) {

let tipoUser = sessionStorage.getItem("TipoUser")
console.log(tipoUser, "Soy tipo user")

const linkPax = "https://test.com/pax_mockUp.html"
const linkRamp = "https://test.com/ramp_mockUp.html"
const linkLogin = "https://test.com/Login/"


function Link() {
    return tipoUser === 14 ? linkPax
         : tipoUser === 15 ? linkRamp
         : linkLogin
}


return (
    <Fragment>
        <a id="idRef" href={Link()}>
            <div className="div_container">
                <div className="div_container-superior">
                    <p>{props.data.Al}{props.data.FlNoOut}</p>
                    <p>{props.data.sAPT}</p>
                </div>
                <div className="div_container-inferior">
                    <div className='ckin_container_abre'>
                        <h5>ABRE CHECK-IN</h5>
                        <p>{props.data.STDOut.slice(10)}</p>
                    </div>
                    <div className='ckin_container_cierra'>
                        <h5>CIERRA CHECK-IN</h5>
                        <p>{props.data.STDOut.slice(10)}</p>
                    </div>
                </div>
            </div>
        </a>
    </Fragment>
);

}

CodePudding user response:

let tipoUser = parseInt(sessionStorage.getItem("TipoUser"))

CodePudding user response:

The issue might be because of the type of the tipoUser variable. This will work for you

let tipoUser = Number(sessionStorage.getItem("TipoUser"))
  • Related