What is the purpose of PropTypes in React?
To enforce the data type of props
To manage component state
To handle user events
To style components
What is the correct syntax for a functional component in React?
const Welcome = () => { ... };
function Welcome(props) { ... }
let Welcome = (props) => { ... }
class Welcome extends React.Component { ... }
What will happen if you update the state directly in a React component?
The component will re-render, but the state change won't be reflected.
Nothing will happen; the state will remain unchanged.
An error will be thrown, and the application will crash.
The component will re-render, and the state change will be reflected correctly.
What are props in React?
Arguments passed to a component
Lifecycle methods of a component
Functions to update the UI
Internal data of a component
In a class component, how do you update the state?
By modifying this.props object
this.props
Using the useState hook
useState
By calling this.setState({ new state })
this.setState({ new state })
Using this.state = { new state } directly
this.state = { new state }
How can you access the original DOM event object in a React event handler?
By using a ref to the DOM element and accessing its event listeners
Through the nativeEvent property of the synthetic event object
nativeEvent
By directly using event.target or event.currentTarget
event.target
event.currentTarget
React doesn't provide access to the original DOM event; it's completely abstracted.
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
Using this keyword inside the event handler
this
By passing the element as an argument to the event handler
As a property of the event object (e.g., event.target)
What is the primary use case for the useEffect hook?
useEffect
To handle form submissions
To perform side effects like data fetching, DOM manipulation, or subscriptions
To render components conditionally
To manage state within a component
What is the main difference between functional components and class components in React?
Functional components are used for complex UI, while class components are used for simple UI.
Class components can have state and lifecycle methods, while functional components cannot.
Functional components are written in JavaScript, while class components are written in JSX.
There is no difference; both are interchangeable.
In React, what is the primary method for handling events in functional components?
Using inline event handlers like onClick={handleClick}
onClick={handleClick}
Using the addEventListener method like in vanilla JavaScript
addEventListener
React components don't handle events directly; you must use a library.
Defining separate event handler methods within the component