Which lifecycle method is called only once, after a component is rendered to the DOM for the first time?
componentWillUnmount()
constructor()
componentDidUpdate()
componentDidMount()
What is the correct way to embed a JavaScript expression inside JSX?
{ expression }
expression
{{ expression }}
( expression )
What is the purpose of the componentWillUnmount() lifecycle method?
To render the component for the first time.
To perform any necessary cleanup operations before a component is removed from the DOM.
To handle user interactions like button clicks.
To update the state based on changes in props.
How does the useEffect Hook in functional components relate to lifecycle methods in class components?
useEffect
useEffect combines the functionality of componentDidMount, componentDidUpdate, and componentWillUnmount.
componentDidMount
componentDidUpdate
componentWillUnmount
useEffect is only used for data fetching.
useEffect is a replacement for componentDidMount only.
There is no relationship between useEffect and lifecycle methods.
How can you access the element that triggered an event within a React event handler?
React doesn't provide a way to access the triggering element
By passing the element as an argument to the event handler
Using this keyword inside the event handler
this
As a property of the event object (e.g., event.target)
event.target
What is the purpose of PropTypes in React?
To style components
To enforce the data type of props
To handle user events
To manage component state
What's a common way to bind event handlers in React class components?
Using bind in the constructor
bind
Using arrow functions in the render method
render
Calling addEventListener within the componentDidMount lifecycle method
addEventListener
Both 'Using bind in the constructor' and 'Using arrow functions in the render method'
What is the purpose of form validation in React?
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.
To style form elements based on user input.
When would it be more appropriate to consider using an uncontrolled component in a React form?
When you need real-time validation and immediate feedback to the user.
When integrating with a third-party library that requires direct access to form elements.
When dealing with a large, complex form where performance optimization is critical.
When you prefer a more imperative approach and direct DOM manipulation.
What is the correct syntax for a functional component in React?
const Welcome = () => { ... };
function Welcome(props) { ... }
let Welcome = (props) => { ... }
class Welcome extends React.Component { ... }