Which of the following is NOT a valid way to bind an event handler in a React class component?
Binding in the constructor: this.handleClick = this.handleClick.bind(this)
this.handleClick = this.handleClick.bind(this)
Using an arrow function in the callback: onClick={() => this.handleClick()}
onClick={() => this.handleClick()}
Using addEventListener directly on the DOM element
addEventListener
Directly passing the method: onClick={this.handleClick}
onClick={this.handleClick}
How do you prevent a useEffect hook from running on every render?
useEffect
By using componentDidMount instead
componentDidMount
By not passing a dependency array
By wrapping the useEffect call in a conditional statement
By passing an empty array [] as the second argument to useEffect
[]
What is the primary purpose of components in React?
To handle user interactions
To break down the UI into independent, reusable pieces
To directly manipulate the DOM
To manage application state
What is the purpose of using key prop in JSX elements within a list?
key
To help React efficiently update and re-render lists.
To give each element a unique identifier for styling purposes.
To associate event handlers with specific elements.
To define the order in which elements should be displayed.
Which of the following is a key benefit of using controlled components in React forms?
Enhanced control over form data and validation.
Simplified state management with reduced boilerplate code.
Seamless integration with external libraries for form handling.
Direct manipulation of the DOM for improved performance.
What is the primary difference between controlled and uncontrolled components in React forms?
Controlled components are suitable for simple forms, while uncontrolled components are ideal for complex forms.
Controlled components are deprecated in React, and uncontrolled components are the recommended approach.
Controlled components directly manipulate the DOM, while uncontrolled components use React's state management.
Controlled components rely on React's state management for form data, while uncontrolled components use DOM references.
How do you represent an empty tag in JSX, like an <img> tag?
<img></>
<img></img>
What is the primary characteristic of a controlled component in React?
It relies on the browser to manage form data.
It uses external libraries for form handling.
It maintains its own internal state for form data.
It directly manipulates the DOM to update form values.
What is the correct syntax for a functional component in React?
const Welcome = () => { ... };
class Welcome extends React.Component { ... }
let Welcome = (props) => { ... }
function Welcome(props) { ... }
Why is event binding often necessary in class components?
To prevent default browser behavior for all events
To allow passing custom arguments to event handlers
To ensure that this refers to the correct component instance inside event handlers
this
Event binding is not necessary in React; it's an older JavaScript concept.