React Flashcards

(86 cards)

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

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
16
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
17
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
18
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
19
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
20
Q

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

A

True

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

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

A

To defer re-rendering of non-urgent updates.

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

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

A

suspense

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

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

A

It allows you to mark updates as non-urgent.

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

What is the new ‘useTransition’ hook used for?

A

To manage state transitions with priority.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
True or False: React 19 has improved support for server-side rendering.
True
26
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.
27
What is the significance of 'React 19's Automatic Error Boundaries'?
They automatically catch errors in component trees.
28
What new feature allows for easier tracking of component performance in React 19?
React Profiler API enhancements
29
What does the 'useId' hook do in React 19?
It generates unique IDs for accessibility and rendering.
30
True or False: React 19 allows for concurrent rendering without breaking existing code.
True
31
What is the purpose of the 'useSyncExternalStore' hook introduced in React 19?
To subscribe to external data sources.
32
What does the new 'SuspenseList' component do?
It coordinates multiple suspense components.
33
What major improvement does React 19 bring to the context API?
React 19 introduces the ability to use a context directly as a provider (e.g., ) instead of requiring .​ **Provider Syntax** This change eliminates boilerplate code for context providers, making state sharing cleaner and more intuitive across components. A codemod will be available to update existing usage, with plans to deprecate the old syntax in future versions.​ **Related Enhancements** The use hook now allows reading context values conditionally or in loops, unlike useContext, which must be called unconditionally at the top level. These updates reduce unnecessary re-renders and improve performance for granular state management.​
34
What is a key benefit of using the 'useInsertionEffect' hook?
It allows for DOM mutations before the browser paints.
35
What is the purpose of the 'useLayoutEffect' hook?
To perform side effects synchronously after all DOM mutations.
36
What is the role of 'React.lazy'?
To enable code-splitting by loading components lazily.
37
What does the 'React.Fragment' component do?
It allows grouping multiple elements without adding extra nodes.
38
What is the significance of the 'useImperativeHandle' hook?
It customizes the instance value that is exposed to parent components.
39
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.
40
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.
41
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.
42
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.
43
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.
44
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.
45
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.
46
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.
47
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.
48
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.
49
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.
50
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.
51
What is concurrent mode in React 19?
Concurrent Mode in React 19 is a set of features that allows React to work on multiple rendering tasks simultaneously, making rendering interruptible and prioritizable. This means React can pause, resume, or even abandon rendering work to handle more urgent updates.
52
What hooks are assigned with React 19 concurrent mode?
useTransition, useOptimistic, (useActionState, useFormStatus uses concurrent features)
53
What is useTransition hook for?
Lets you mark updates as non-urgent, allowing React to prioritize urgent interactions and keep the UI responsive during heavy computations or data fetching. It returns a pending state and a function to start a transition.
54
What is useOptimistic hook for?
Enables optimistic UI updates by allowing the UI to reflect the expected result of an async operation immediately, while the actual update happens in the background. Once the async action completes, the UI updates accordingly.
55
What is useActionState hook for?
Simplifies managing form state, async updates, and errors by consolidating them into a single API, reducing the need for multiple useState calls when handling complex form logic.
56
What is useFormStatus hook for?
Provides real-time status of a parent
, such as whether a submission is pending. This is especially useful in design systems for disabling buttons or showing loading indicators during concurrent form submissions.
57
What is a typical use case for the useTransition hook in React 19?
useTransition is used to mark updates as non-urgent, allowing React to prioritize urgent interactions (like typing or clicking) over background tasks (like filtering a large list), keeping the UI responsive during heavy computations or async operations.
58
When should you use the useOptimistic hook in React 19?
useOptimistic is ideal when you want to show immediate UI feedback for an async action (such as adding an item to a list) before the server confirms the change, enabling optimistic UI updates.
59
What problem does the useFormStatus hook solve in React 19?
useFormStatus provides components (like buttons) with real-time status of their parent form, such as whether a submission is pending, which is useful for disabling buttons or showing loading indicators during concurrent form submissions.
60
What is useDeferredValue?
useDeferredValue is a React hook introduced in React 18 that allows you to defer updating a part of the UI, making your application feel more responsive during heavy or expensive renders.
61
How useDeferredValue works?
When you wrap a value with useDeferredValue, React will prioritize urgent updates (like user input) and delay updating the parts of your UI that depend on the deferred value. This means the UI can display "stale" or previous data for a short period, while React processes the expensive update in the background. Once React has spare time, it updates the UI with the latest value.
62
When to use useDeferredValue?
Filtering or rendering very large lists Live previews (e.g., markdown editors) Complex data visualizations
63
Difference Between useDeferredValue and useTransition
64
65
What is the Virtual DOM in React?
An **in-memory representation** of the UI; React diffs the old vs. new virtual DOM trees and applies only the minimal real DOM changes (reconciliation).
66
What is React reconciliation?
The process React uses to **diff two virtual DOM trees** and compute the minimal set of real DOM mutations needed to update the UI.
67
What is React Fiber?
React's internal reconciliation engine (since v16); enables **incremental rendering** by splitting work into pauseable/resumable units — foundation for concurrent features.
68
What is the difference between `useEffect` and `useLayoutEffect`?
`useEffect` runs **after paint** (asynchronous). `useLayoutEffect` runs **synchronously after DOM mutations but before paint** — use for measuring DOM elements.
69
What does the `useEffect` dependency array control?
- `[]` — runs only on mount/unmount - `[a, b]` — re-runs when a or b changes - Omitted — runs after **every render**
70
What does `React.memo` do?
Memoizes a functional component; **skips re-render** if props haven't changed (shallow comparison of each prop).
71
What does `useMemo` do?
Memoizes a **computed value** — only recomputes when dependencies change. Use for expensive calculations.
72
What does `useCallback` do?
Memoizes a **function reference** — returns the same function instance unless dependencies change. Prevents child re-renders when passing callbacks as props.
73
What is the difference between `useMemo` and `useCallback`?
`useMemo(() => value, deps)` caches a **value**. `useCallback(fn, deps)` caches a **function** (equivalent to `useMemo(() => fn, deps)`).
74
What is `useReducer` and when do you prefer it over `useState`?
`useReducer(reducer, initialState)` — prefer when state has **complex transitions**, multiple sub-values, or when next state depends on previous state + action.
75
What is React Context and what is its performance gotcha?
Provides values deep in the component tree without prop-drilling. Gotcha: **all consumers re-render** whenever the context value changes, even if only part of the value changed.
76
What is a custom hook? (React)
A function starting with `use` that **composes built-in hooks** — extracts reusable stateful logic from components.
77
What are React Server Components?
Components that render **on the server**, don't ship JavaScript to the client, and can directly access server resources (DB, filesystem). Available in Next.js App Router.
78
What is the difference between React Server Components and client components?
Server components: no JS bundle, no hooks, async by default, server-only access. Client components: `'use client'` directive, can use hooks and browser APIs.
79
What is React Suspense?
Lets components "wait" for async data before rendering; shows a **fallback** UI (e.g., spinner) until the data or lazy-loaded component is ready.
80
What is the `key` prop in React and why is it required for lists?
A **stable unique identifier** for list items; tells React which element maps to which between renders — enables efficient reconciliation instead of re-mounting.
81
What is the problem with using array index as `key` in React?
If list order changes (insert, delete, sort), React may reuse wrong component instances → **stale state and visual bugs**.
82
What is the React component lifecycle equivalent using hooks?
- Mount: `useEffect(() => { ... }, [])` - Update: `useEffect(() => { ... }, [dep])` - Unmount: return cleanup function from `useEffect`
83
What triggers a React re-render?
State change (`setState`/`useState`), context value change, parent re-render (unless `React.memo` blocks it), or `forceUpdate`.
84
What is prop drilling and how do you solve it?
Passing props through many layers of components. Solutions: **React Context**, **state management library** (Zustand, Redux), or **component composition**.
85
What is `useRef` used for in React?
1. Accessing a **DOM element** directly. 2. Storing a **mutable value** that doesn't trigger re-render when changed.
86
What is the difference between controlled and uncontrolled components in React?
**Controlled**: form value managed by React state (`value` + `onChange`). **Uncontrolled**: DOM manages its own state; accessed via `ref`.