In a class component, how do you update the state?
Using this.state = { new state } directly
this.state = { new state }
By calling this.setState({ new state })
this.setState({ new state })
By modifying this.props object
this.props
Using the useState hook
useState
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 purpose of using the event.preventDefault() method within a form submission handler in React?
event.preventDefault()
To submit the form data asynchronously without using AJAX.
To prevent the browser from refreshing the page.
To clear the form data after submission.
To validate the form data before submission.
Which lifecycle method is called only once, after a component is rendered to the DOM for the first time?
componentWillUnmount()
constructor()
componentDidMount()
componentDidUpdate()
What happens if a prop is not provided to a component with a default prop defined?
The prop will be undefined
An error is thrown
The component will not render
The default prop value is used
What is the purpose of form validation in React?
To send data to the server for validation.
To ensure data integrity and prevent invalid submissions.
To automatically submit the form when all fields are filled.
To style form elements based on user input.
What is the second argument of the useEffect Hook used for?
useEffect
It provides access to the previous state and props.
It specifies a list of dependencies that trigger the effect when they change.
It defines the effect to be executed.
It indicates the effect should be executed only once, like componentDidMount.
componentDidMount
In JSX, how would you set the 'class' attribute for an element?
What is the correct way to embed a JavaScript expression inside JSX?
( expression )
{ expression }
expression
{{ expression }}
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 using a third-party library specifically for error display.
By conditionally rendering error messages based on validation results.