What is the primary role of 'Synthetic Events' in React?
To directly manipulate the DOM without using React's virtual DOM
To enable asynchronous event handling in React components
To provide a cross-browser consistent interface for handling DOM events
To prevent default browser actions for all events
What is the recommended approach for handling events in React class components?
Use global event listeners to manage events outside the component
Event handling is not typically done within React class components
Define event handlers as separate methods within the class and bind them in the constructor
Define event handlers as inline arrow functions within the render method
What is the correct syntax for defining default props in a functional component in React?
MyComponent.defaultProps = { name: 'John' };
export default function MyComponent(props = { name: 'John' }) { }
function MyComponent(props) { props.defaultProps = { name: 'John' }; }
defaultProps = { name: 'John' }(MyComponent);
What is the second argument of the useEffect Hook used for?
useEffect
It defines the effect to be executed.
It indicates the effect should be executed only once, like componentDidMount.
componentDidMount
It specifies a list of dependencies that trigger the effect when they change.
It provides access to the previous state and props.
What is the purpose of the useState hook in React?
useState
To style components dynamically
To fetch data from an API
To handle user input events
To manage and update the state of a functional component
What will happen if you update the state directly in a class component instead of using this.setState()?
this.setState()
The application will crash
The state will be updated, but the component won't re-render
An error will be thrown
The component will re-render automatically
Which type of component in React is primarily used for presenting data and does not manage its own state?
Functional Component
State Component
Class Component
Higher-Order Component
What happens if a prop is not provided to a component with a default prop defined?
The prop will be undefined
The default prop value is used
The component will not render
An error is thrown
What are Synthetic Events in React?
Events related to state changes within a React component
Events triggered only by synthetic user actions (like bot interactions)
Native browser events directly exposed by the DOM
React's custom event objects that wrap native events
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
By defining methods inside the component class
Using inline event handlers directly in JSX