React behind the scenes Flashcards
What is the purpose of the render phase in React?
The render phase prepares a list of updates to be made to the DOM.
How does the commit phase differ from the render phase in terms of synchronization?
The commit phase is synchronous, while the render phase can be paused and resumed.
What is the primary responsibility of the commit phase in React?
The commit phase writes updates to the DOM, making changes visible to the user.
What happens to the work in progress fiber tree after the commit phase?
The work in progress fiber tree becomes the current tree for the next render cycle.
Which library is responsible for writing updates to the DOM in React?
React DOM is the library responsible for the commit phase and interacting with the DOM.
Why is React designed to be independent from the platform where elements will be shown?
React can be used with various hosts, including web browsers, native mobile apps, and more, making it versatile.
What is the purpose of the reconciliation process, and what does it result in?
Reconciliation minimizes DOM updates by finding the smallest number of updates needed to reflect the latest state changes.
Is the render phase synchronous or asynchronous, and why?
The render phase is asynchronous to allow for concurrent features and prevent the JavaScript engine from being blocked.
How does the commit phase ensure a consistent user interface?
The commit phase is synchronous, performing all DOM updates in one go.
What triggers the visual update of the user interface on the screen after the commit phase?
The browser repaints the screen to make the DOM updates visible to the user.
What is the conceptual difference between React components, component instances, and React elements?
Components are like blueprints for the user interface, component instances are physical manifestations of components with their own state and lifecycle, and React elements are JavaScript objects that represent the result of using a component in code.
How can you describe a React component in terms of its purpose?
A React component is like a blueprint or template for describing a piece of the user interface.
What is the primary function of a React component?
A React component is a JavaScript function that returns React elements, describing the structure of the UI.
How does React create component instances from components?
React creates component instances each time the component is used in code, by calling the component function.
What defines the lifecycle of a React component instance?
Each component instance has its own lifecycle, including birth, existence, and eventual termination.
In practice, how are the terms “component” and “component instance” often used interchangeably?
While technically different, “component” and “component instance” are often used interchangeably in common usage.
What is a React element, and how is it created?
A React element is a big immutable JavaScript object created by React when calling component functions. It represents the UI structure.
What information does a React element contain?
A React element contains all the information required to create DOM elements for the component instance.
How are React elements related to DOM elements in the rendering process?
React elements are converted to DOM elements and rendered onto the screen by the browser.
How can you view a component instance in your code?
You can log a component instance to the console by directly using the component and passing it to the console.log() function.
What is the output when you log a component instance to the console?
Logging a component instance displays a React element representing the component, with its type and optional props.
Why does React use the symbol “$$typeof” in React elements?
React uses the “$$typeof” symbol as a security feature to protect against cross-site scripting attacks, ensuring that symbols cannot be transmitted via JSON.