Performance & Optimization Flashcards

1
Q

Why is using the index as a key in React lists a bad idea?

A

If the list order changes, it can lead to performance issues and bugs as React uses keys to reconcile the DOM.

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

How can you prevent a component from re-rendering?

A

Using React.memo() for functional components or shouldComponentUpdate lifecycle method for class components.

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

Name some tools you can use to diagnose performance issues in React apps.

A

React DevTools, Chrome DevTools, the Profiler API, and Lighthouse.

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