Create New Post

React JS MCQs 6

  1. In React, which method is called before the component is removed from the DOM?

    • a) componentWillUnmount (Correct Answer)
    • b) componentDidMount
    • c) componentDidUpdate
    • d) componentWillMount
  2. 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
  3. Which of the following is a valid way to define a React functional component?

    • a) function MyComponent() {}
    • b) const MyComponent = () => {}
    • c) class MyComponent extends React.Component {}
    • d) All of the above (Correct Answer)
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. What is the purpose of the children prop in a React component?

    • a) It represents the child components rendered inside the component (Correct Answer)
    • b) It defines the default content of the component
    • c) It passes data from parent to child components
    • d) It defines the structure of the component
  10. Which of the following statements about React components is true?

    • a) Functional components can have lifecycle methods
    • b) Class components can return multiple elements without using a wrapper element
    • c) Functional components are simpler and easier to read and write compared to class components (Correct Answer)
    • d) All of the above

Comments

Leave a Reply

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

18623