React Advanced Flashcards

(40 cards)

1
Q

What is server-side rendering (SSR) in React?

A

Rendering React components on the server and sending HTML to the client for faster load and SEO.

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

What is hydration in SSR?

A

The process where React attaches event listeners to server-rendered HTML on the client.

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

What are the main differences between SSR and client-side rendering?

A

SSR renders HTML on the server and improves SEO/load time; CSR renders in the browser after JS loads.

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

How does Next.js enhance React applications?

A

It provides SSR, file-based routing, API routes, and static generation for production-ready apps.

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

What is static site generation (SSG)?

A

A method to pre-render pages at build time for performance and scalability.

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

What are React Suspense and Concurrent Mode?

A

Suspense allows lazy loading of components; Concurrent Mode enables interruptible rendering for better responsiveness.

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

What is the difference between useTransition and useDeferredValue?

A

useTransition lets you mark updates as non-urgent; useDeferredValue postpones a value update until more urgent tasks finish.

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

What is React Fiber?

A

A complete rewrite of React’s core algorithm to enable concurrency and incremental rendering.

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

How do you handle authentication in a React app?

A

Using tokens (JWT), context or state for user session, and protected routes via React Router.

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

How does context API compare to Redux?

A

Context is simpler for small global states; Redux offers more control, middleware, and dev tools.

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

What is Redux Toolkit?

A

A standardized, efficient way to write Redux logic with less boilerplate.

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

What is the purpose of middleware in Redux?

A

To intercept and handle actions for tasks like async calls (e.g., Redux Thunk, Redux Saga).

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

What is the React Profiler API?

A

A tool to measure the performance of React components during render cycles.

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

How can you reduce bundle size in React apps?

A

By code splitting, tree shaking, using React.lazy, and avoiding unnecessary libraries.

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

What is tree shaking?

A

A process during build that removes unused code from bundles.

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

What are render props?

A

A technique for sharing code between components using a function prop that returns JSX.

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

What is a higher-order component (HOC)?

A

A function that takes a component and returns a new component with enhanced behavior.

18
Q

What are the downsides of HOCs?

A

They can lead to wrapper hell, harder debugging, and prop collisions.

19
Q

What is useImperativeHandle?

A

A hook to customize the instance value exposed when using React.forwardRef.

20
Q

What is React.forwardRef?

A

A function to pass refs from parent to child components.

21
Q

What is the difference between controlled and uncontrolled components?

A

Controlled are managed by React state; uncontrolled store state in the DOM.

22
Q

How do you test React components?

A

Using Jest and React Testing Library to write unit and integration tests.

23
Q

What is shallow rendering in testing?

A

Rendering only the component under test without its children to isolate behavior.

24
Q

What is the role of React Testing Library?

A

To test components from the user’s perspective, focusing on accessibility and actual DOM output.

25
How do you mock API calls in React tests?
Using libraries like MSW (Mock Service Worker) or jest.fn() for simulating responses.
26
What is a custom hook and when would you use one?
A reusable function using other hooks to share logic across components.
27
What are some rules of hooks?
Only call hooks at the top level and only from React functions or custom hooks.
28
What is the purpose of React.StrictMode?
To identify unsafe lifecycle methods, highlight potential issues, and ensure compatibility with future features.
29
What does key prop help with in React lists?
It helps React track list item changes and optimize re-renders.
30
Why is reconciliation important in React?
It enables React to efficiently update the DOM by comparing virtual DOM trees.
31
How does React handle synthetic events?
It wraps native events in a cross-browser wrapper for consistent behavior.
32
What is useRef and when would you use it?
To persist values across renders or reference DOM nodes.
33
What is the difference between useRef and createRef?
useRef is for function components; createRef is mainly for class components.
34
What is a render cycle in React?
The process of rendering a component, committing changes, and triggering effects.
35
How do you optimize re-renders in large component trees?
Using memoization (React.memo, useMemo), useCallback, and selective rendering.
36
What is useReducer and how does it compare to useState?
useReducer is better for complex state logic; it manages state transitions via actions.
37
How do you structure a scalable React project?
By organizing components, hooks, services, and state logically using feature- or domain-based folders.
38
What are atomic design principles in UI development?
A methodology dividing UI into atoms, molecules, organisms, templates, and pages.
39
What is a stale closure in React and how can you fix it?
An outdated variable in a closure; fix using refs or dependencies in useEffect.
40
How do you integrate WebSockets in React?
Use useEffect to establish the connection and clean up on unmount, managing state updates with events.