In React functional components, how do you typically handle events?
Events are not handled in functional components, only in class components
By creating separate event listener functions outside the component
Using inline event handlers directly in JSX
By defining methods inside the component class
What will happen if you update the state directly in a React component?
An error will be thrown, and the application will crash.
Nothing will happen; the state will remain unchanged.
The component will re-render, and the state change will be reflected correctly.
The component will re-render, but the state change won't be reflected.
How can you display validation errors to the user in a React form?
By using browser alerts to notify the user of invalid input.
By logging errors to the console for debugging purposes.
By conditionally rendering error messages based on validation results.
By relying solely on HTML5's built-in validation error messages.
In React, what is the primary method for handling events in functional components?
React components don't handle events directly; you must use a library.
Defining separate event handler methods within the component
Using the addEventListener method like in vanilla JavaScript
addEventListener
Using inline event handlers like onClick={handleClick}
onClick={handleClick}
Why is it generally not recommended to mutate the DOM directly in React?
Direct DOM manipulation can lead to inconsistencies between the actual DOM and React's virtual DOM
React's event system automatically prevents DOM manipulation
DOM manipulation is slow and inefficient in modern browsers
React doesn't have access to the DOM, so manipulation is impossible
How do class components in React typically handle events?
By defining methods on the class that act as event handlers
Class components cannot handle events; only functional components can
Using inline arrow functions directly in the JSX
By relying on external state management libraries for event handling
In a class component, how do you update the state?
Using this.state = { new state } directly
this.state = { new state }
Using the useState hook
useState
By calling this.setState({ new state })
this.setState({ new state })
By modifying this.props object
this.props
What is the primary role of 'Synthetic Events' in React?
To enable asynchronous event handling in React components
To directly manipulate the DOM without using React's virtual DOM
To prevent default browser actions for all events
To provide a cross-browser consistent interface for handling DOM events
What is the correct syntax for defining default props in a functional component in React?
export default function MyComponent(props = { name: 'John' }) { }
function MyComponent(props) { props.defaultProps = { name: 'John' }; }
defaultProps = { name: 'John' }(MyComponent);
MyComponent.defaultProps = { name: 'John' };
What is the purpose of form validation in React?
To style form elements based on user input.
To automatically submit the form when all fields are filled.
To ensure data integrity and prevent invalid submissions.
To send data to the server for validation.