Prep Plan for Offline Drive
1. Why React?
- Key Concepts to Cover:
- React's component-based architecture and reusability.
- React's declarative programming model for building UIs.
- Comparison with traditional approaches (imperative vs declarative).
- Unidirectional data flow and how React improves app performance.
- JSX: How it simplifies writing UI with JavaScript.
- Practice Questions:
- Why is React considered a popular library for building user interfaces?
- What is the difference between imperative and declarative programming? Why does React favor declarative?
- Explain how components help in reusability and modularity in large-scale applications.
- Task:
- Write a simple React component that displays a list of items passed as props.
- Build a small React application that uses state and props to manage data flow in a component hierarchy.
- Write a comparison between React and a traditional approach like jQuery for building interactive UIs.
2. Virtual DOM (vDOM)
- Key Concepts to Cover:
- What is the Virtual DOM (vDOM)?
- How React uses the vDOM to improve performance.
- Difference between the vDOM and the real DOM.
- How React updates the vDOM, compares changes, and then updates the actual DOM.
- Practice Questions:
- What is the Virtual DOM in React, and how does it work?
- Why does the vDOM make React faster than directly manipulating the real DOM?
- Explain the process of updating the vDOM when a component's state changes.
- Task:
- Write a simple React app and explain what happens to the vDOM and real DOM when the state is updated.
- Create a demo showing how React uses the vDOM to reduce the number of manipulations on the real DOM.
3. Reconciliation
- Key Concepts to Cover:
- What reconciliation is and how React decides what changes need to be applied to the DOM.
- How React compares the current vDOM tree with the previous one.
- The efficiency of reconciliation: Only the necessary changes are made to the DOM.
- Key importance for optimizing lists: Why React needs
key props for elements in lists.
- Practice Questions:
- What is reconciliation in React? How does React efficiently update the DOM using this process?
- Explain how React uses keys during reconciliation and why they are important.
- What happens when keys are missing or incorrectly used in a list of elements?
- Task:
- Write a React app where a list of items is rendered and update the list dynamically. Use
key props and explain how React handles the reconciliation process.
- Write a function that demonstrates the incorrect usage of keys and explain the performance consequences.
4. Diffing Algorithm
- Key Concepts to Cover:
- What is the Diffing Algorithm and how React uses it to determine the minimum set of changes needed to update the DOM.
- The O(n) complexity of the algorithm, which makes it efficient even for large applications.
- How the diffing algorithm compares elements at the same level in the tree to avoid unnecessary updates.
- React's heuristics: Element-by-element comparison and handling child components.
- Practice Questions:
- What is the Diffing Algorithm in React, and how does it contribute to the efficiency of the vDOM?
- How does React’s Diffing Algorithm ensure optimal performance when re-rendering components?
- What are the key heuristics React follows while diffing two trees?
- Task:
- Implement a small React app and explain, step-by-step, how the Diffing Algorithm works during a re-render when state changes.
- Demonstrate how React's Diffing Algorithm handles a scenario where sibling nodes are reordered or removed.