简体   繁体   中英

react implement condition to show and hide

There are two textbox JO and PO

  1. If user both should hide.
  2. If admin hide JO and show PO.
  3. if superadmin show both

Need to implement above logic in react or javascript?

If i understand your question correctly you can do like this:

If i understand your question correctly you can do like this:



 const role = getRole()

{(role !== "user" && role !== "admin") || role==='superadmin' && <TextBoxJo />}
{(role !== "user" && role === "admin") || role==='superadmin' && <TextBoxPo />}

you can even put these conditions and use that function, there are multiple ways to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM