Create New Post

React JS MCQs 3

  1. What is the purpose of the useCallback hook in React?

    • a) To memoize functions so that they are not recreated on every render (Correct Answer)
    • b) To manage state within functional components
    • c) To fetch data from an API
    • d) To define context providers
  2. How can you optimize performance in React applications?

    • a) By using PureComponent or memoization for functional components (Correct Answer)
    • b) By increasing the number of re-renders
    • c) By adding more unnecessary DOM elements
    • d) By using synchronous rendering
  3. What is the purpose of the key prop in React?

    • a) To specify the type of component
    • b) To define the initial state of a component
    • c) To uniquely identify elements in an array of children and improve performance during reconciliation (Correct Answer)
    • d) To define CSS classes for styling
  4. How does React handle events?

    • a) React uses a synthetic event system that normalizes events across different browsers (Correct Answer)
    • b) React relies on native browser events exclusively
    • c) React doesn't support event handling
    • d) React events are handled asynchronously
  5. What is the purpose of the useContext hook in React?

    • a) To manage component state
    • b) To handle context within class components
    • c) To access context values in functional components (Correct Answer)
    • d) To fetch data from an external API
  6. What is the key difference between state and props in React?

    • a) State is immutable, while props are mutable
    • b) State is passed from parent to child components, while props are managed internally by components
    • c) State is managed internally by components and can be changed, while props are passed from parent to child components and are immutable (Correct Answer)
    • d) State and props are interchangeable concepts in React
  7. How can you pass data from a child to a parent component in React?

    • a) By using the setState method
    • b) By using props (Correct Answer)
    • c) By using context
    • d) By using event listeners
  8. What is the purpose of the useMemo hook in React?

    • a) To perform data fetching
    • b) To subscribe to changes in state or props
    • c) To memoize expensive calculations and optimize performance (Correct Answer)
    • d) To manage side effects in functional components
  9. What is the purpose of the useReducer hook in React?

    • a) To manage complex state logic and perform state transitions (Correct Answer)
    • b) To manage component lifecycle events
    • c) To create reusable custom hooks
    • d) To fetch data from an API
  10. Which method is used to handle errors in React components?

    • a) componentDidCatch (Correct Answer)
    • b) componentDidError
    • c) componentDidFail
    • d) componentDidErrorBound

Comments

Leave a Reply

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

84020