Create New Post

React JS MCQs 12

  • 111. What is the purpose of the `useEffect` hook in React?
    • a) To manage component state
    • b) To perform side effects after every render (Correct Answer)
    • c) To create reusable custom hooks
    • d) To fetch data from an API
  • 112. How do you conditionally render elements in React?
    • a) Using the if-else statement inside the JSX
    • b) Using the ternary operator inside the JSX (Correct Answer)
    • c) Using the switch-case statement inside the JSX
    • d) Using the while loop inside the JSX
  • 113. 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
  • 114. How do you define a reusable component in React?
    • a) By creating a function or class that returns JSX (Correct Answer)
    • b) By using a global variable to store the component
    • c) By including HTML code directly in the render method
    • d) By importing a component from an external library
  • 115. What is the purpose of the `key` prop when rendering a list of components in React?
    • a) To define the styling for each component in the list
    • b) To specify the order of the components in the list
    • c) To help React identify which items have changed, are added, or are removed in the list (Correct Answer)
    • d) To define the initial state of each component in the list


Leave a Reply

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