What is the correct syntax for defining default props in a functional component in React?
export default function MyComponent(props = { name: 'John' }) { }
defaultProps = { name: 'John' }(MyComponent);
MyComponent.defaultProps = { name: 'John' };
function MyComponent(props) { props.defaultProps = { name: 'John' }; }
How can you display validation errors to the user in React?
By directly manipulating the DOM to insert error messages.
By relying solely on browser console logs for error reporting.
By conditionally rendering error messages based on validation results.
By using a third-party library specifically for error display.
Which lifecycle method is called only once, after a component is rendered to the DOM for the first time?
constructor()
componentWillUnmount()
componentDidMount()
componentDidUpdate()
How do you pass data from a parent component to a child component in React?
Using events
Using props
Using state
Using refs
What's the difference between JSX attributes and HTML attributes?
JSX attributes can only be strings, while HTML attributes can be any data type.
There is no difference, they are the same.
JSX attributes are used for styling, while HTML attributes are for functionality.
JSX attributes are written in camelCase, while HTML attributes are lowercase.
Which of the following is a key difference between functional components and class components in React?
Functional components cannot receive props, while class components can
Functional components are stateless, while class components can have state
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
What is the correct syntax for a functional component in React?
let Welcome = (props) => { ... }
class Welcome extends React.Component { ... }
function Welcome(props) { ... }
const Welcome = () => { ... };
When would it be more appropriate to consider using an uncontrolled component in a React form?
When you prefer a more imperative approach and direct DOM manipulation.
When dealing with a large, complex form where performance optimization is critical.
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.
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
An error will be thrown
The component will re-render automatically
The application will crash
In React, what is the primary method for handling events in functional components?
Defining separate event handler methods within the component
Using the addEventListener method like in vanilla JavaScript
addEventListener
Using inline event handlers like onClick={handleClick}
onClick={handleClick}
React components don't handle events directly; you must use a library.