What is the purpose of using key prop in JSX elements within a list?
key
To help React efficiently update and re-render lists.
To associate event handlers with specific elements.
To give each element a unique identifier for styling purposes.
To define the order in which elements should be displayed.
When a component's state or props change, React decides whether to update the actual DOM. What is this process called?
Virtual DOM diffing
State reconciliation
Component rehydration
Lifecycle management
What is the primary characteristic of a controlled component in React?
It relies on the browser to manage form data.
It maintains its own internal state for form data.
It uses external libraries for form handling.
It directly manipulates the DOM to update form values.
What is the primary purpose of components in React?
To directly manipulate the DOM
To manage application state
To break down the UI into independent, reusable pieces
To handle user interactions
What happens if a prop is not provided to a component with a default prop defined?
An error is thrown
The prop will be undefined
The default prop value is used
The component will not render
Which of the following is a key difference between functional components and class components in React?
Functional components are stateless, while class components can have state
Functional components cannot receive props, while class components can
Functional components are used for complex UI logic, while class components are for simple elements
Functional components are written in JavaScript, while class components use TypeScript
How do you define default props for a functional component in React?
Inside the component's function body
Default props are not supported for functional components
By passing them as arguments to the component
Using the defaultProps property of the component function
defaultProps
What is the primary role of 'Synthetic Events' in React?
To directly manipulate the DOM without using React's virtual DOM
To prevent default browser actions for all events
To provide a cross-browser consistent interface for handling DOM events
To enable asynchronous event handling in React components
What will happen if you update the state directly in a React component?
An error will be thrown, and the application will crash.
The component will re-render, and the state change will be reflected correctly.
Nothing will happen; the state will remain unchanged.
The component will re-render, but the state change won't be reflected.
How do you prevent a useEffect hook from running on every render?
useEffect
By using componentDidMount instead
componentDidMount
By passing an empty array [] as the second argument to useEffect
[]
By not passing a dependency array
By wrapping the useEffect call in a conditional statement