vendredi 23 novembre 2018

Use React's and if statement

So I have a function that I want to link to different pages of my site when a specific string is active (in this case when the string is 'got' from local storage). See below please:

displayCharacterProfile() { let getCharacterName = localStorage.getItem("characterName");

    if(getCharacterName == "littlefinger") {
        <Link to="/littlefinger"></Link>
    }
    if(getCharacterName == "tywin") {
        <Link to="/tywin"></Link>
    }

}

The displayCharacterProfile function is attached to a button using onClick in the render and return ().

Any quick help would be greatly appreciated guys! Thank you :-)

Aucun commentaire:

Enregistrer un commentaire