M3- How React works? Flashcards

How React uses Virtual DOM?

1
Q

What is the main challenge with updating the browser DOM directly?

A

Updating the browser DOM directly is considered expensive because it is time-intensive for the browser. Every time the DOM is updated, the browser has to reflow and repaint the page, which can slow down performance, especially for complex web pages.

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

How does React address the performance issue of direct DOM manipulation?

A

React addresses this issue by using a virtual DOM. The virtual DOM is a lightweight, in-memory representation of the actual browser DOM. By using this virtual DOM, React can efficiently update the browser DOM without needing to re-render the entire page.

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

What is the virtual DOM in React?

A

The virtual DOM is a virtual representation of the browser DOM that exists only in memory. It is created and managed by React and is used to track changes to the web page efficiently.

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

How does React use the virtual DOM to update the browser DOM?

A

React uses the virtual DOM to compare the new virtual DOM with the previous version. This comparison, known as reconciliation, helps React determine which elements have changed. React then updates only those specific elements in the browser DOM, rather than re-rendering the entire page.

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

What is the process called when React compares the virtual DOM with the previous version?

A

The process is called “reconciliation.” During reconciliation, React identifies the differences between the new virtual DOM and the previous virtual DOM to determine which parts of the browser DOM need to be updated.

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

What steps does React follow when a component is updated?

A

When a component is updated:

  1. React creates a new virtual DOM representation for the component.
  2. React compares this new virtual DOM with the previous version to identify changes.
  3. React updates only the changed elements in the actual browser DOM.
  4. The browser DOM is then updated to reflect these changes on the web page.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the benefits of using a virtual DOM in React?

A
  • Improved performance due to efficient, targeted updates.
  • Reduced re-rendering of the entire page, leading to faster application response times.
  • Enhanced user experience with smoother interactions and quicker updates.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why does React’s approach to updating the DOM lead to better performance?

A

React’s approach leads to better performance by minimizing the amount of work the browser needs to do. Instead of re-rendering the entire page, React updates only the elements that have changed, which makes the application faster and more responsive.

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