Create New Post

React JS MCQs 7

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

    • a) To create references to DOM elements or React components (Correct Answer)
    • b) To manage component state
    • c) To subscribe to context changes
    • d) To perform asynchronous operations
  2. In React, what is the recommended way to handle forms?

    • a) Using regular HTML form elements
    • b) Using controlled components where form data is handled by React state (Correct Answer)
    • c) Using uncontrolled components where form data is handled by the DOM
    • d) Using Redux for form state management
  3. Which hook is used to perform side effects in functional components?

    • a) useState
    • b) useEffect (Correct Answer)
    • c) useContext
    • d) useReducer
  4. 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
  5. In React, which method is called before the component is removed from the DOM?

    • a) componentWillUnmount (Correct Answer)
    • b) componentDidMount
    • c) componentDidUpdate
    • d) componentWillMount
  6. What is the primary role of ReactDOM in a React application?

    • a) To handle routing and navigation
    • b) To manage global application state
    • c) To render React components into the DOM (Correct Answer)
    • d) To handle server-side rendering
  7. What is the purpose of the useMemo hook in React?

    • a) To memoize the result of a function so that it is only recomputed when its dependencies change (Correct Answer)
    • b) To perform side effects in functional components
    • c) To manage component state
    • d) To subscribe to context changes
  8. In React, what does it mean to lift state up?

    • a) It refers to managing state at the lowest level of the component tree
    • b) It refers to passing state from child to parent components
    • c) It refers to moving state to a common ancestor component to share it between sibling components (Correct Answer)
    • d) It refers to removing state from a component
  9. What is the purpose of the defaultProps property in a React component?

    • a) To define default values for props (Correct Answer)
    • b) To set the initial state of a component
    • c) To define the default styling for a component
    • d) To handle default event behavior
  10. In React, what is the purpose of the key prop when rendering a list of components?

    • a) It defines the style of each list item
    • b) It helps React identify which items have changed, are added, or are removed in the list (Correct Answer)
    • c) It sets the initial state of each list item
    • d) It specifies the order of the list items

Comments

Leave a Reply

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

59520