What is the correct syntax for defining default props in a functional component in React?
export default function MyComponent(props = { name: 'John' }) { }
MyComponent.defaultProps = { name: 'John' };
defaultProps = { name: 'John' }(MyComponent);
function MyComponent(props) { props.defaultProps = { name: 'John' }; }
What is the primary purpose of components in React?
To handle user interactions
To manage application state
To directly manipulate the DOM
To break down the UI into independent, reusable pieces
What is the correct syntax for a functional component in React?
function Welcome(props) { ... }
class Welcome extends React.Component { ... }
let Welcome = (props) => { ... }
const Welcome = () => { ... };
What's a common way to bind event handlers in React class components?
Calling addEventListener within the componentDidMount lifecycle method
addEventListener
componentDidMount
Both 'Using bind in the constructor' and 'Using arrow functions in the render method'
bind
render
Using bind in the constructor
Using arrow functions in the render method
What is the purpose of PropTypes in React?
To handle user events
To enforce the data type of props
To style components
To manage component state
Which of the following JSX expressions is INVALID?
<span>This is incorrect {</span>
How can you access the element that triggered an event within a React event handler?
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
React doesn't provide a way to access the triggering element
How do uncontrolled components in React handle form data?
By using refs to directly access and manage DOM values.
By sending an HTTP request to the server on every input change.
By storing the data in a global state management library.
By relying on data binding between the form and component state.
What is the purpose of using key prop in JSX elements within a list?
key
To define the order in which elements should be displayed.
To help React efficiently update and re-render lists.
To give each element a unique identifier for styling purposes.
To associate event handlers with specific elements.
What's the difference between JSX attributes and HTML attributes?
There is no difference, they are the same.
JSX attributes are written in camelCase, while HTML attributes are lowercase.
JSX attributes are used for styling, while HTML attributes are for functionality.
JSX attributes can only be strings, while HTML attributes can be any data type.