Create New Post

React JS MCQs 2

  1. 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
  2. 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)
  3. 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
  4. 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
  5. 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()
  6. 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
  7. 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
  8. 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()
  9. 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
  10. Which of the following is NOT a hook provided by React?

    • a) useState()
    • b) useEffect()
    • c) useContext()
    • d) createClass()

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

17673