Advanced React Concepts Flashcards

1
Q

What is context in React?

A

Context provides a way to pass data through the component tree without having to pass props down manually at every level.

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

How does React’s Concurrent Mode enhance user interfaces?

A

It allows React to interrupt a long-running render to handle high-priority events like user input, leading to more responsive apps.

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

What is a higher-order component (HOC)?

A

A HOC is a function that takes a component and returns a new component with added props or functionality.

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

Explain the purpose of the React.memo() function.

A

It memoizes the rendered output of a component, preventing unnecessary renders if props don’t change.

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

What is the purpose of useState in React?

A

To manage local state within a functional component.

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

When should you use useEffect?

A

When you want to perform side effects (like fetching data, manual DOM manipulations, etc.) in functional components.

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

What is useContext used for?

A

To access the context for a component without wrapping it in a Consumer.

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

When is it beneficial to use useReducer?

A

When state logic is more complex and involves multiple sub-values, or when the next state depends on the previous state.

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

What is the main purpose of useCallback?

A

To memoize functions so they don’t get recreated every render, especially when passed to child components as props to prevent unnecessary renders.

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

Why would you use useMemo?

A

To memoize expensive computations so they are only re-computed when specific inputs change.

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

When should you use useRef?

A

For accessing and interacting with DOM elements directly, or for keeping a mutable reference to a value that doesn’t trigger a re-render when it changes.

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

What does useImperativeHandle do?

A

It customizes the instance value that is exposed when using React.forwardRef.

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

When is useLayoutEffect used?

A

When you need to perform synchronous visual DOM updates, similar to useEffect but it fires synchronously after all DOM mutations.

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

What is useDebugValue used for?

A

It’s used in custom hooks to display a label in React DevTools next to this hook.

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

What is React’s context?

A

A mechanism for passing data directly to nested components without prop-drilling, often used for global state or theming.

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

What’s the purpose of Error Boundaries in React?

A

Components that catch JavaScript errors in their child component tree, log those errors, and display a fallback UI.

17
Q

What are Uncontrolled Components in React?

A

Components that store their own state internally and you query the DOM directly using refs to find their current values when needed.

18
Q

What are Controlled Components in React?

A

Components where React controls the form elements’ values (like an input’s value) and changes are handled by a function passed as a prop.

19
Q

Explain the importance of keys in React lists.

A

Keys help React identify which items have changed, are added, or removed, enabling efficient and accurate UI updates.

20
Q

How does React’s Lazy loading work?

A

Using React.lazy(), components are loaded dynamically with import(), aiding in performance optimization by splitting the app into chunks.

21
Q

Explain React Fragments.

A

Fragments allow grouping multiple child elements without adding extra nodes to the DOM, useful for returning multiple elements from a component.

22
Q

What are React Portals?

A

Portals provide a way to render children into a DOM node outside of the parent DOM hierarchy, often used for modals or pop-ups.

23
Q

What is Concurrent Mode in React?

A

An experimental feature that allows React to interrupt rendering to work on multiple tasks simultaneously, optimizing user interactivity.

24
Q

What’s the primary use of React.memo?

A

It’s a higher order component that memoizes the rendered output, preventing unnecessary renders if the props haven’t changed.

25
Q

What is the purpose of Suspense in React?

A

It lets your components “wait” for something before rendering, commonly used with React.lazy() to show fallback content like a loading spinner.

26
Q

What is React’s forwardRef?

A

A tool to forward refs from a parent component to a child component, useful for direct child DOM manipulation or accessing child instance methods.