What are Synthetic Events in React?
React's custom event objects that wrap native events
Native browser events directly exposed by the DOM
Events triggered only by synthetic user actions (like bot interactions)
Events related to state changes within a React component
What is the purpose of using the event.preventDefault() method within a form submission handler in React?
event.preventDefault()
To clear the form data after submission.
To submit the form data asynchronously without using AJAX.
To prevent the browser from refreshing the page.
To validate the form data before submission.
Which of the following is a common approach for implementing form validation in React?
Utilizing a dedicated form validation library.
Writing custom validation functions within the component.
All of the above.
Using HTML5 form validation attributes.
Which of the following is NOT a valid way to bind an event handler in a React class component?
Using addEventListener directly on the DOM element
addEventListener
Directly passing the method: onClick={this.handleClick}
onClick={this.handleClick}
Using an arrow function in the callback: onClick={() => this.handleClick()}
onClick={() => this.handleClick()}
Binding in the constructor: this.handleClick = this.handleClick.bind(this)
this.handleClick = this.handleClick.bind(this)
How do you prevent a useEffect hook from running on every render?
useEffect
By wrapping the useEffect call in a conditional statement
By using componentDidMount instead
componentDidMount
By not passing a dependency array
By passing an empty array [] as the second argument to useEffect
[]
Which type of component in React is primarily used for presenting data and does not manage its own state?
Class Component
State Component
Functional Component
Higher-Order Component
What is the primary difference between controlled and uncontrolled components in React forms?
Controlled components are deprecated in React, and uncontrolled components are the recommended approach.
Controlled components are suitable for simple forms, while uncontrolled components are ideal for complex forms.
Controlled components rely on React's state management for form data, while uncontrolled components use DOM references.
Controlled components directly manipulate the DOM, while uncontrolled components use React's state management.
How does the useEffect Hook in functional components relate to lifecycle methods in class components?
useEffect combines the functionality of componentDidMount, componentDidUpdate, and componentWillUnmount.
componentDidUpdate
componentWillUnmount
There is no relationship between useEffect and lifecycle methods.
useEffect is a replacement for componentDidMount only.
useEffect is only used for data fetching.
What is the primary use case for the useEffect hook?
To handle form submissions
To perform side effects like data fetching, DOM manipulation, or subscriptions
To render components conditionally
To manage state within a component
Why is it generally not recommended to mutate the DOM directly in React?
DOM manipulation is slow and inefficient in modern browsers
React doesn't have access to the DOM, so manipulation is impossible
React's event system automatically prevents DOM manipulation
Direct DOM manipulation can lead to inconsistencies between the actual DOM and React's virtual DOM