-
What is the purpose of keys in React lists?
- a) To uniquely identify list items and help React identify which items have changed, added, or removed (Correct Answer)
- b) To apply styling to list items
- c) To determine the order of list items
- d) Keys are not used in React lists
-
Which method is used to conditionally render components in React?
- a) renderIf()
- b) renderConditionally()
- c) render() method with if-else statements
- d) render() method with conditional rendering syntax like ternary operators or logical && (Correct Answer)
-
What is the purpose of PropTypes in React?
- a) To define types for React components
- b) To specify default values for props
- c) To validate the props passed to a component (Correct Answer)
- d) PropTypes are not used in React
-
Which of the following is used to manage state across multiple components in React?
- a) Redux (Correct Answer)
- b) useState hook
- c) Context API
- d) Props drilling
-
In React, what is the recommended way to perform side effects such as data fetching or DOM manipulation?
- a) Inside the constructor of the component
- b) Inside the render method
- c) Using lifecycle methods like componentDidMount() or useEffect() hook (Correct Answer)
- d) Using setTimeout()
-
Which of the following is true about PureComponent in React?
- a) It is deprecated in favor of functional components
- b) It automatically implements shouldComponentUpdate() with a shallow prop and state comparison (Correct Answer)
- c) It is used for defining stateful components
- d) It is used for server-side rendering in React
-
What is the purpose of the ref attribute in React?
- a) To reference an external JavaScript file
- b) To create a reference to a DOM element or a React component instance (Correct Answer)
- c) To define the relative path of a component
- d) To specify the location of a resource
-
Which method is called after the component is updated and the DOM has been re-rendered in React?
- a) componentDidUpdate() (Correct Answer)
- b) componentWillUpdate()
- c) componentWillMount()
- d) componentDidRender()
-
What is the purpose of React Fragments?
- a) To create virtual DOM elements
- b) To improve performance by reducing unnecessary re-renders
- c) To group multiple children without adding extra nodes to the DOM (Correct Answer)
- d) To apply animations to React components
-
Which of the following is NOT a hook provided by React?
- a) useState()
- b) useEffect()
- c) useContext()
- d) createClass()
Comments