How does the useEffect Hook in functional components relate to lifecycle methods in class components?
useEffect
There is no relationship between useEffect and lifecycle methods.
useEffect is only used for data fetching.
useEffect is a replacement for componentDidMount only.
componentDidMount
useEffect combines the functionality of componentDidMount, componentDidUpdate, and componentWillUnmount.
componentDidUpdate
componentWillUnmount
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
As a property of the event object (e.g., event.target)
event.target
Using this keyword inside the event handler
this
What is the correct way to embed a JavaScript expression inside JSX?
{{ expression }}
( expression )
expression
{ expression }
How do you prevent a useEffect hook from running on every render?
By not passing a dependency array
By wrapping the useEffect call in a conditional statement
By using componentDidMount instead
By passing an empty array [] as the second argument to useEffect
[]
What is the recommended approach for handling events in React class components?
Use global event listeners to manage events outside the component
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
Event handling is not typically done within React class components
How do you define default props for a functional component in React?
By passing them as arguments to the component
Default props are not supported for functional components
Using the defaultProps property of the component function
defaultProps
Inside the component's function body
Which of the following JSX expressions is INVALID?
<span>This is incorrect {</span>
What will happen if you update the state directly in a class component instead of using this.setState()?
this.setState()
The state will be updated, but the component won't re-render
The application will crash
The component will re-render automatically
An error will be thrown
What is the second argument of the useEffect Hook used for?
It indicates the effect should be executed only once, like componentDidMount.
It defines the effect to be executed.
It provides access to the previous state and props.
It specifies a list of dependencies that trigger the effect when they change.
How do class components in React typically handle events?
Using inline arrow functions directly in the JSX
Class components cannot handle events; only functional components can
By relying on external state management libraries for event handling
By defining methods on the class that act as event handlers