What is the purpose of form validation in React?
To ensure data integrity and prevent invalid submissions.
To send data to the server for validation.
To style form elements based on user input.
To automatically submit the form when all fields are filled.
What is the purpose of PropTypes in React?
To enforce the data type of props
To style components
To manage component state
To handle user events
What is the correct way to embed a JavaScript expression inside JSX?
{ expression }
{{ expression }}
( expression )
expression
How do you pass data from a parent component to a child component in React?
Using refs
Using events
Using state
Using props
What is the second argument of the useEffect Hook used for?
useEffect
It specifies a list of dependencies that trigger the effect when they change.
It defines the effect to be executed.
It provides access to the previous state and props.
It indicates the effect should be executed only once, like componentDidMount.
componentDidMount
What is the main difference between functional components and class components in React?
There is no difference; both are interchangeable.
Functional components are used for complex UI, while class components are used for simple UI.
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.
Which of the following is a key benefit of using controlled components in React forms?
Enhanced control over form data and validation.
Seamless integration with external libraries for form handling.
Direct manipulation of the DOM for improved performance.
Simplified state management with reduced boilerplate code.
What is the purpose of event.preventDefault() in React event handling?
event.preventDefault()
To detach the event handler after it has been executed once
To prevent the default behavior of the event (like form submission)
To stop the event from bubbling up the component tree
To cancel the event entirely and prevent any further actions
Why is event binding often necessary in class components?
To prevent default browser behavior for all events
To ensure that this refers to the correct component instance inside event handlers
this
To allow passing custom arguments to event handlers
Event binding is not necessary in React; it's an older JavaScript concept.
How do you prevent a useEffect hook from running on every render?
By wrapping the useEffect call in a conditional statement
By passing an empty array [] as the second argument to useEffect
[]
By not passing a dependency array
By using componentDidMount instead