Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Conditional rendering

In React, there is no special syntax for writing conditions. Instead, you’ll use the same techniques as you use when writing regular JavaScript code. For example, you can use an if statement to conditionally include JSX:

 let content ; 
if ( isLoggedIn ) {
content = < AdminPanel /> ;
} else {
content = < LoginForm /> ;
}
return (
< div >
{ content }
</ div >
) ;

If you prefer more compact code, you can use the conditional ? operator. Unlike if, it works inside JSX:

 < div > 
{ isLoggedIn ? (
< AdminPanel />
) : (
< LoginForm />
) }
</ div >

When you don’t need the else branch, you can also use a shorter logical && syntax:

 < div > 
{ isLoggedIn && < AdminPanel /> }
</ div >

All of these approaches also work for conditionally specifying attributes. If you’re unfamiliar with some of this JavaScript syntax, you can start by always using if...else.

If you want to change selection, open document below and click on "Move attachment"

Quick Start – React
bove example, style={{}} is not a special syntax, but a regular {} object inside the style={ } JSX curly braces. You can use the style attribute when your styles depend on JavaScript variables. <span>Conditional rendering In React, there is no special syntax for writing conditions. Instead, you’ll use the same techniques as you use when writing regular JavaScript code. For example, you can use an if statement to conditionally include JSX: let content; if (isLoggedIn) { content = <AdminPanel />; } else { content = <LoginForm />; } return ( <div> {content} </div> ); If you prefer more compact code, you can use the conditional ? operator. Unlike if, it works inside JSX: <div> {isLoggedIn ? ( <AdminPanel /> ) : ( <LoginForm /> )} </div> When you don’t need the else branch, you can also use a shorter logical && syntax: <div> {isLoggedIn && <AdminPanel />} </div> All of these approaches also work for conditionally specifying attributes. If you’re unfamiliar with some of this JavaScript syntax, you can start by always using if...else. Rendering lists You will rely on JavaScript features like for loop and the array map() function to render lists of components. For example, let’s say you have an array of products: cons


Summary

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

Details



Discussion

Do you want to join discussion? Click here to log in or create user.