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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

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

True or False: React 19 supports automatic batching of updates.

22
Q

What is the purpose of the new ‘useDeferredValue’ hook in React 19?

A

To defer re-rendering of non-urgent updates.

23
Q

Fill in the blank: React 19 introduces a new way to manage __________ in concurrent mode.

24
Q

What does the ‘startTransition’ API do in React 19?

A

It allows you to mark updates as non-urgent.

25
What is the new 'useTransition' hook used for?
To manage state transitions with priority.
26
True or False: React 19 has improved support for server-side rendering.
True
27
What is the key feature of the new 'React Server Components' in React 19?
They allow components to be rendered on the server and sent to the client.
28
What is the significance of 'React 19's Automatic Error Boundaries'?
They automatically catch errors in component trees.
29
What new feature allows for easier tracking of component performance in React 19?
React Profiler API enhancements
30
What does the 'useId' hook do in React 19?
It generates unique IDs for accessibility and rendering.
31
True or False: React 19 allows for concurrent rendering without breaking existing code.
True
32
What is the purpose of the 'useSyncExternalStore' hook introduced in React 19?
To subscribe to external data sources.
33
What does the new 'SuspenseList' component do?
It coordinates multiple suspense components.
34
What major improvement does React 19 bring to the context API?
Better performance and simpler updates.
35
What is a key benefit of using the 'useInsertionEffect' hook?
It allows for DOM mutations before the browser paints.
36
What is the purpose of the 'useLayoutEffect' hook?
To perform side effects synchronously after all DOM mutations.
37
What is the role of 'React.lazy'?
To enable code-splitting by loading components lazily.
38
What does the 'React.Fragment' component do?
It allows grouping multiple elements without adding extra nodes.
39
What is the significance of the 'useImperativeHandle' hook?
It customizes the instance value that is exposed to parent components.
40
What is the core difference between React state and signals?
React state (with hooks) re-renders the entire component on change, while signals update only the parts of the UI that use the signal's value, avoiding full component re-renders.
41
How do signals track dependencies differently from React state?
Signals automatically track which components use their value and update only those, while React requires explicit dependency arrays in hooks like useEffect.
42
What is a signal in the context of frontend development?
A signal is an object with a .value property that notifies subscribed components to update when its value changes, enabling granular UI updates.
43
How does React handle state changes by default?
React re-runs the entire component function and its child components when state changes, potentially causing unnecessary re-renders.
44
What setup is required to use signals in React?
You can use signals in React by installing the @preact/signals-react package and importing the signal object where needed.
45
What is a potential drawback of using signals in large React applications?
Signals can introduce debugging complexity and may not scale as well as advanced state management tools like Redux in very large applications.
46
Can signals be used with class components in React?
Yes, signals can be used inside or outside of components, including class components, unlike hooks which are limited to function components.
47
What is a limitation of signals regarding debugging?
Signals can make debugging more complex because state is managed through a centralized store, making it harder to trace data flow.
48
In what types of projects are signals most beneficial?
Signals are best suited for simple to medium-sized applications where performance and simplicity are priorities.
49
How do signals compare to Redux and Context API for state management?
Signals offer a simpler, more lightweight alternative for small to medium apps, while Redux and Context are better for complex, large-scale state management.
50
What is automatic dependency tracking in the context of signals?
Automatic dependency tracking means signals detect which components use their value and update them when the value changes, without manual setup.
51
Why might React not fully adopt signals as a default approach?
Signals can complicate the component execution model and require developers to manage which values are signals versus plain values, potentially increasing code complexity.