Core React Concepts

Conditional Rendering

Render alternate UI states based on conditions such as loading, auth, or error states.

Basic patterns

tsx
{isLoading && <Spinner />}
{hasError ? <ErrorView /> : <DataView />}

Early returns for clarity

tsx
if (!user) return <LoginPrompt />;
return <Dashboard user={user} />;

Render null when needed

tsx
if (!isVisible) return null;

Real-world states

Most pages should handle:

  • Loading state
  • Empty state
  • Error state
  • Success/data state

Next, we will render dynamic lists correctly with keys.