Return to site

⚛️ REACT quiz: ternary operator

· frontend,react

In this component, how do you display whether the user was logged in or not?

render() { const isLoggedIn = this.state.isLoggedIn;
return (
〈div〉
The user is:
〈/div〉
);
}

* The user is loggedIn ? logged in : not logged in.

* Write a function to check the login status.

* The user is {isLoggedIn = "no"}.

* The user is {isLoggedIn ? "logged in." : "not logged in"}.

#react #quiz #programming

Answer:

You can use a ternary operator or an if/else statement to conditionally render the appropriate message based on the value of isLoggedIn. Here's an example using a ternary operator:

render() { const isLoggedIn = this.state.isLoggedIn;
return (
〈div〉
The user is: {isLoggedIn ? 'logged in' : 'not logged in'}
〈/div〉
);
}