How do you represent an empty tag in JSX, like an <img> tag?
<img></img>
<img></>
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 you prefer a more imperative approach and direct DOM manipulation.
When dealing with a large, complex form where performance optimization is critical.
When integrating with a third-party library that requires direct access to form elements.
What is the purpose of the componentWillUnmount() lifecycle method?
componentWillUnmount()
To render the component for the first time.
To handle user interactions like button clicks.
To update the state based on changes in props.
To perform any necessary cleanup operations before a component is removed from the DOM.
What is the correct syntax for defining default props in a functional component in React?
function MyComponent(props) { props.defaultProps = { name: 'John' }; }
export default function MyComponent(props = { name: 'John' }) { }
defaultProps = { name: 'John' }(MyComponent);
MyComponent.defaultProps = { name: 'John' };
Which of the following JSX expressions is INVALID?
<span>This is incorrect {</span>
What will happen if you update the state directly in a React component?
Nothing will happen; the state will remain unchanged.
The component will re-render, but the state change won't be reflected.
An error will be thrown, and the application will crash.
The component will re-render, and the state change will be reflected correctly.
When a component's state or props change, React decides whether to update the actual DOM. What is this process called?
Virtual DOM diffing
Component rehydration
State reconciliation
Lifecycle management
In React, what is the primary method for handling events in functional components?
Using inline event handlers like onClick={handleClick}
onClick={handleClick}
Defining separate event handler methods within the component
Using the addEventListener method like in vanilla JavaScript
addEventListener
React components don't handle events directly; you must use a library.
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
As a property of the event object (e.g., event.target)
event.target
By passing the element as an argument to the event handler
Using this keyword inside the event handler
this
What is the main difference between functional components and class components in React?
There is no difference; both are interchangeable.
Functional components are written in JavaScript, while class components are written in JSX.
Class components can have state and lifecycle methods, while functional components cannot.
Functional components are used for complex UI, while class components are used for simple UI.