Skip to main content
D
React
React Conditional Rendering

React Conditional Rendering

React conditional rendering shows different components based on state.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

React lets developers show completely different UI elements depending on a specific condition. For example, if a user is logged in, show the dashboard. If they are not logged in, show the login screen.

Example

Example
1/* this renders conditionally */
2function Greeting({ isLoggedIn }) {
3  if (isLoggedIn) {
4    return <h2>Welcome back!</h2>;
5  }
6  return <h2>Please log in.</h2>;
7}

Key Points

  • You can use standard JavaScript `if` statements.
  • The `&&` operator renders an element if true.
  • The ternary operator `? :` acts as an inline if-else statement.
  • Returning `null` hides the component completely.

Up Next

Continue your journey with the next topic.

Go to React Lists & Keys