What is React?
- UI becomes hard to manage
- Code becomes messy and repetitive
- Updating UI is slow
- Difficult to scale applications
-> With React:
- UI is divided into reusable components
- Faster updates using Virtual DOM
- Better code organization
- Easy to maintain large applications
** Examples:
-Updating cart items without page reload
-Live search suggestions
-Dynamic dashboards
-Social media feeds
-
What are the main features of React?
** Features:
1. Component-Based Architecture
→ Break UI into small reusable pieces
→ Example: Navbar, Card, Button
2. Virtual DOM
→ Faster updates and better performance
3. JSX
→ HTML-like syntax inside JavaScript
→ Makes UI code readable
4. One-Way Data Binding
→ Data flows in one direction (Parent → Child)
→ Easy debugging and control
5. Reusability
→ Write once, use multiple times
→ Reduces code duplication
6. Fast Rendering
→ Updates only changed parts of UI
7. Props (Data Passing System)
→ Used to pass data from parent to child components
→ Read-only (cannot be modified)
→ Helps in component communication
8. State (Data Management)
→ Used to manage data inside a component
→ When state changes → UI updates automatically
9. Hooks
→ Special functions to use state and other features in functional components
** Common Hooks:
- useState() → manage state
10. Lifecycle Management
→ Controls what happens when component:
- Updates
- Unmounts
→ Mostly handled using useEffect in modern React
11. Strong Ecosystem
→ Huge community support
→ Popular libraries:
→ Routing
→ State management
→ UI libraries
-
What is JSX?
** Why Needed?
→ Without JSX:-
- Writing UI in pure JavaScript in complex.
→ With JSX:-
- Code becomes readable
- UI structure looks like HTML
** Example:-
-
How does JSX work?
** How It Works:
- Babel converts JSX into JavaScript
- React uses React.createElement()
- Elements are rendered to the DOM
**Example:
// JSX Code
const element = Hello;
// Converted Code
const element = React.createElement("h1", null, "Hello");
-> Browsers understand only JavaScript, not JSX.
** How It Works:-
I. Virtual DOM is created
II. When data changes, a new Virtual DOM is created
III. React compares old and new Virtual DOM (diffing)
IV. Only changed parts are updated in real DOM
-> Without Virtual DOM:
- Full DOM updates -> slow performance
- Faster rendering
**Result:
- Better performance
- Smooth user experience
-
How does React update the UI?
-
What is a React component?
-
What is the difference between a React element and a component?
-
What are props in React?
-
What is state in React?
-
What is the difference between props and state?
-
What is a functional component?
-
What is a class component?
-
What is the difference between functional and class components?
-
What are fragments in React?
-
What is the purpose of the key prop?
-
What happens if we use array index as key?
-
What are controlled components?
-
What are uncontrolled components?
-
How does React handle forms?
-
What is event handling in React?
-
What are synthetic events?
-
What is conditional rendering in React?
-
How do you render a list in React?
-
What are default props?
-
What is prop drilling?
-
What is lifting state up?
-
What are React Hooks?
-
Why were Hooks introduced?
-
What is useState?
-
What is useEffect?
-
What is the dependency array in useEffect?
-
What are side effects in React?
-
What are keys in React lists?
-
What is JSX transpiled into?
-
What is ReactDOM?
-
What is the difference between React and ReactDOM?
-
What are stateless components?
-
What are stateful components?
-
What are inline conditional expressions?
-
What is the children prop?
-
What is React.StrictMode?
-
What are PropTypes?
-
What is create-react-app?
-
What is the difference between HTML and React event handling?
-
What are portals in React?
-
What are refs in React?
-
What is useRef?
-
What is memoization?
-
What is React.memo?