React Flashcards

1
Q

Where are Server Components and Client Components rendered?

A

Server Components render exclusively on the server and never re-render on the client. Client Components render on both the server (during SSR/SSG) and client (during hydration).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What directive marks a component as a Client Component?

A

The ‘use client’ directive at the top of a file signals a Client Component, enabling client-side interactivity and hooks like useState.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why can’t Server Components use React hooks like useState?

A

Server Components lack access to browser APIs and client-side state, making hooks reliant on client runtime incompatible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do Server Components improve bundle size?

A

They exclude server-only code (e.g., large libraries like marked) from client bundles, reducing JavaScript payloads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the primary advantage of Server Components over SSR?

A

Server Components enable granular, component-level server rendering without requiring full-page reloads or hydration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you nest a Server Component inside a Client Component?

A

Use the children prop in the Client Component as a placeholder, then pass the Server Component as a child in the parent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the role of Suspense in Server Components?

A

Suspense streams Server Component outputs incrementally, allowing placeholders (e.g., loading spinners) while content loads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do Server Components handle data fetching?

A

They fetch data directly on the server during rendering, eliminating client-server waterfalls and enabling parallel data+UI streaming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Can Server Components import Client Components?

A

Yes, but Client Components cannot import Server Components due to runtime environment incompatibilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between Server Components and SSR?

A

SSR generates full-page HTML on the server, while Server Components render specific UI parts on the server and integrate with client-side React.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do Server Components interact with browser APIs like localStorage?

A

They cannot—Server Components run on the server, so browser APIs must be used in Client Components or via server-side abstractions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is “hydration” in the context of Client Components?

A

Hydration attaches client-side JavaScript to server-rendered HTML, enabling interactivity and state management.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why are Server Components not hydrated?

A

They produce static HTML without client-side interactivity, eliminating hydration costs and JavaScript overhead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do Server Components impact SEO?

A

They improve SEO by default, as search engines receive fully rendered HTML without requiring client-side JavaScript execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a “shared component” in RSC architecture?

A

A component that runs on both server and client, often used as a starting point before specialization into Server/Client Components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do Server Actions work in React 19?

A

Server Actions are functions annotated with ‘use server’ that run on the server, invoked from Client Components via form submissions or events.

17
Q

What is the renderToPipeableStream API used for?

A

It serializes Server Component outputs into a streamable format, enabling progressive HTML delivery to the client.

18
Q

How does RSC handle dynamic data updates?

A

By revalidating server-rendered content via Server Actions or revalidatePath, triggering server re-renders without full-page reloads.

19
Q

Why are keys important when rendering lists in RSC?

A

Keys help React track dynamic list items across server/client renders, ensuring stable updates and minimizing unnecessary re-renders.

20
Q

What is the main criticism of React Server Components?

A

Critics argue RSC blurs server/client boundaries, risking tightly coupled architectures reminiscent of early PHP-like spaghetti code.