Conditional Rendering and Lists
Part of the React course
Almost every screen you have ever used shows one thing instead of another depending on some condition: a "you have new messages" banner that only appears when there are new messages, a spinner that only shows while something is loading. And almost every screen shows more than one of something: a list of orders, a grid of products, a feed of posts.
Picture a doorman standing in front of a room. Before letting anyone through, he checks exactly one thing. If the check passes, the person walks in. If it fails, nothing happens at all, no explanation, no placeholder, just silence and a closed door. That is exactly the job of && (logical AND) inside a JSX expression: when you write condition && <SomeElement />, React renders <SomeElement /> only if condition is...
Want to learn React Conditional Rendering and Lists in a real environment?
Click below, get a fresh Linux box with React ready to go, and work through Conditional Rendering and Lists hands-on with an AI tutor that knows your code.
Start this lessonConditional Rendering and ListsWhat you'll learn
- && for show/hide
- Ternary for either/or
- Mapping arrays to JSX
- The key prop
- Why keys need to be stable
Read this lesson in your language
All lessons in this course
17 lessons- 1What is React?25 min
- 2JSX and Components30 min
- 3Props30 min
- 4State with useState35 min
- 5Handling Events30 min
- 6Conditional Rendering and Lists30 min
- 7Forms and Controlled Inputs35 min
- 8Effects with useEffect40 min
- 9Data Fetching40 min
- 10Component Composition35 min
- 11Context and useContext35 min
- 12useReducer35 min
- 13Custom Hooks35 min
- 14Performance and Memoization35 min
- 15Routing with React Router40 min
- 16Testing React Components40 min
- 17Capstone: Todo App60 min
