React Intermediate Flashcards

(20 cards)

1
Q

What are React hooks?

A

Functions that let functional components use state and lifecycle features (e.g.

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

What problem does useEffect solve compared to class lifecycle methods?

A

It allows side effects (like API calls) in functional components

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

How can you optimize performance in a React application?

A

By using memoization (React.memo

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

What is React.memo and how does it work?

A

A higher-order component that memoizes functional components to avoid unnecessary re-renders if props haven’t changed.

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

What is the purpose of useMemo?

A

To memoize the result of a computation so it’s only recalculated when dependencies change.

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

What is the purpose of useCallback?

A

To memoize a function reference so it doesn’t get redefined on every render unless dependencies change.

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

How does context API work in React?

A

It allows you to pass global data (like themes or user info) without prop drilling through many layers.

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

What is prop drilling and how can it be avoided?

A

Passing props through multiple levels unnecessarily; useContext or state management libraries can help avoid it.

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

What are controlled vs uncontrolled inputs?

A

Controlled inputs are managed by React state; uncontrolled inputs use refs and native DOM state.

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

How do you implement error boundaries in React?

A

By creating a class component with componentDidCatch and getDerivedStateFromError methods to catch and display errors.

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

What is lazy loading in React?

A

A technique to load components only when they are needed

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

What is code splitting?

A

Breaking the app into smaller bundles so parts are only loaded when needed

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

What is the difference between useEffect and useLayoutEffect?

A

useLayoutEffect runs synchronously after render but before paint; useEffect runs asynchronously after paint.

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

What is a custom hook in React?

A

A reusable function that starts with “use” and abstracts shared logic using other hooks.

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

How do you prevent unnecessary re-renders in child components?

A

Use React.memo

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

What is reconciliation in React?

A

The process of comparing the virtual DOM with the previous one and updating only the parts that changed.

17
Q

What happens if you call setState in useEffect without dependencies?

A

It causes an infinite loop because the effect runs after every render and updates state.

18
Q

How do you fetch data in a React component safely?

A

Use useEffect to call an async function

19
Q

How do you manage forms with complex validation in React?

A

Use libraries like Formik or React Hook Form

20
Q

How do portals work in React?

A

They allow rendering children into a different part of the DOM