Module 32: Components and Props

Lesson 5 of 5 · 15–25 minutes

Showing nothing, something, or a message

🏠The everyday picture

A shop's display window: when there's stock, it shows the goods; when there isn't, a sign says "New stock arriving Friday", not an empty, confusing window.

📘What it really is

🖱️Try it

Create an EmptyState component with a message prop. Show it in each panel when its list is empty. Test by temporarily making all sample enquiries closed. Show an "Urgent" label on cards whose subject contains "urgent" (ignoring case).

✅Quick check

{enquiries.length && <List />} shows "0" on screen when empty. Why, and what's the fix?

Show the answer

0 is falsy so && returns it, and React prints numbers. Use enquiries.length > 0 && ....

Why does every list need an empty state?

Show the answer

An empty space looks broken; a message tells people what's going on and what to do next.

← PreviousLists and keys
ProLearners Assist