Why is it generally not recommended to mutate the DOM directly in React?
React's event system automatically prevents DOM manipulation
React doesn't have access to the DOM, so manipulation is impossible
DOM manipulation is slow and inefficient in modern browsers
Direct DOM manipulation can lead to inconsistencies between the actual DOM and React's virtual DOM
Which of the following is a key benefit of using controlled components in React forms?
Simplified state management with reduced boilerplate code.
Enhanced control over form data and validation.
Direct manipulation of the DOM for improved performance.
Seamless integration with external libraries for form handling.
What is the purpose of the componentWillUnmount() lifecycle method?
componentWillUnmount()
To perform any necessary cleanup operations before a component is removed from the DOM.
To render the component for the first time.
To update the state based on changes in props.
To handle user interactions like button clicks.
What is the recommended approach for handling events in React class components?
Define event handlers as inline arrow functions within the render method
Define event handlers as separate methods within the class and bind them in the constructor
Use global event listeners to manage events outside the component
Event handling is not typically done within React class components
What is the correct way to embed a JavaScript expression inside JSX?
{{ expression }}
( expression )
{ expression }
expression
When a component's state or props change, React decides whether to update the actual DOM. What is this process called?
Component rehydration
State reconciliation
Lifecycle management
Virtual DOM diffing
Which lifecycle method is called only once, after a component is rendered to the DOM for the first time?
constructor()
componentDidMount()
componentDidUpdate()
Which of the following is a key difference between functional components and class components in React?
Functional components cannot receive props, while class components can
Functional components are stateless, while class components can have state
Functional components are written in JavaScript, while class components use TypeScript
Functional components are used for complex UI logic, while class components are for simple elements
How do you pass data from a parent component to a child component in React?
Using props
Using refs
Using state
Using events
How does the useEffect Hook in functional components relate to lifecycle methods in class components?
useEffect
useEffect is only used for data fetching.
There is no relationship between useEffect and lifecycle methods.
useEffect combines the functionality of componentDidMount, componentDidUpdate, and componentWillUnmount.
componentDidMount
componentDidUpdate
componentWillUnmount
useEffect is a replacement for componentDidMount only.