Conditional Rendering and Lists

Harry · 22 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

Conditional Rendering

Use logical AND and ternaries inside JSX; use early returns for empty or loading states.

{isLoggedIn ? <Dashboard /> : <Login />}
{showMenu && <Menu />}

Rendering Lists

Map arrays to elements and always supply a stable key from your data - never the array index for reorderable lists.

{users.map(u => <li key={u.id}>{u.name}</li>)}

Key Points

  • Handle loading, empty and error states first.
  • Keys give elements stable identity.
  • Missing keys cause lost state and slow renders.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in