+ 1

Can we use a ternary operator under return in react hooks ??

Hii all !, Const [ status, setStatus ] = useState(true) //Under return status === true ? <div> Login <div/> : <div> Logout <div/> Output -- login Can anyone suggest a better way of doing this ? Thank you!

8th Aug 2020, 4:12 PM
Aditya
Aditya - avatar
2 odpowiedzi
+ 2
Try this component App function App () { const [ status, setStatus ] = useState(true) // under return return ( <div> { status ? <div> Login </div> : <div> Logout </div> } </div> ) }
9th Aug 2020, 12:57 AM
Calviղ
Calviղ - avatar
+ 1
Thank you Calviղ
9th Aug 2020, 5:11 AM
Aditya
Aditya - avatar