What is a key advantage of using a controlled component for a file input in React?
Explanation:
With a controlled file input, the selected file data is stored within your component's state, giving you more control over handling, previewing, and uploading the file.
Which of the following JSX expressions is INVALID?
Explanation:
JSX expressions must be valid JavaScript. You cannot have an opening curly brace '{' without a corresponding closing brace '}' within a JSX expression.
What is the purpose of form validation in React?
Explanation:
Form validation is crucial for maintaining data quality. It involves checking if the user's input meets predefined criteria (e.g., required fields, email format) before it's submitted.
How does the useEffect
Hook in functional components relate to lifecycle methods in class components?
Explanation:
The useEffect
Hook allows you to perform side effects within functional components. By specifying dependencies, it can mimic the behavior of componentDidMount
(no dependencies), componentDidUpdate
(dependencies), and componentWillUnmount
(return a cleanup function).
What happens if a prop is not provided to a component with a default prop defined?
Explanation:
Default props act as fallback values when a prop is not explicitly passed to the component.
How do uncontrolled components in React handle form data?
Explanation:
Uncontrolled components in React don't rely on the component's state for form data. Instead, they use refs to directly interact with the DOM, allowing you to extract values when needed.
What are Synthetic Events in React?
Explanation:
Synthetic events are plain JavaScript objects created by React that hold information about an event across different browsers. They provide a consistent API and prevent cross-browser inconsistencies.
Which of the following is a key benefit of using controlled components in React forms?
Explanation:
Controlled components excel at providing granular control over form data. By storing data in React's state, you can easily implement validation, dynamic updates, and custom form logic.
What is the correct syntax for a functional component in React?
Explanation:
This is the most common and recommended syntax for defining functional components in modern React, using arrow functions.
What is the purpose of PropTypes in React?
Explanation:
PropTypes help ensure that components receive the correct data type for their props, improving code reliability.