Matheus Borges
Matheus Borges

Reputation: 47

How to conditionally add a text to a component?

I want to add this line that says that the ninja is a master but only if the belt is red or black. I think I'm mixing up this type of function I'm trying to use.

<div>{isMaster = () => {
    if (n.belt === "black" || n.belt === "red") {
       return "Master";
    } else {
       return null;
    }
}}</div>

Upvotes: 1

Views: 64

Answers (2)

Zohaib Ijaz
Zohaib Ijaz

Reputation: 22875

You just need one line. Don't create a function there

<div>{(n.belt === "black" || n.belt === "red") && "Master"}</div>

Upvotes: 2

keikai
keikai

Reputation: 15146

<div>
  {(n.belt === "black" || n.belt === "red") && "Master"}
</div>

Upvotes: 2

Related Questions