Create New Post

React JS MCQs 4

  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. Which of the following statements is true about React portals?

    • a) React portals allow you to render components outside the DOM hierarchy of the parent component (Correct Answer)
    • b) React portals are used to create reusable UI components
    • c) React portals are deprecated in favor of other techniques
    • d) React portals are used for server-side rendering only
  3. What is the purpose of the forwardRef function in React?

    • a) To forward props from parent to child components
    • b) To forward DOM attributes from parent to child components
    • c) To forward refs from parent to child components (Correct Answer)
    • d) To forward context from parent to child components
  4. Which of the following is NOT a valid lifecycle method in React?

    • a) componentWillMount
    • b) componentWillUpdate
    • c) componentWillReceiveProps
    • d) componentWillUnmount (Correct Answer)
  5. What is the purpose of the React.Fragment component in React?

    • a) To create a new React component
    • b) To group multiple elements without adding extra nodes to the DOM (Correct Answer)
    • c) To define global styles for the entire application
    • d) To manage component state
  6. Which of the following statements about React context is true?

    • a) React context is used to manage component state
    • b) React context allows you to pass data through the component tree without having to pass props down manually (Correct Answer)
    • c) React context is primarily used for styling components
    • d) React context is a replacement for Redux
  7. What is the purpose of the createRef function in React?

    • a) To create references to DOM elements or React components
    • b) To create new React components
    • c) To create new context objects
    • d) To create references to functional components (Correct Answer)
  8. Which of the following is NOT a valid way to style components in React?

    • a) Inline styles
    • b) External CSS files
    • c) Styled-components library
    • d) Using <style> tags inside JSX (Correct Answer)
  9. What is the purpose of the dangerouslySetInnerHTML attribute in React?

    • a) To sanitize HTML input before rendering it
    • b) To escape special characters in HTML input
    • c) To set the inner HTML of a React component from a string (Correct Answer)
    • d) To prevent XSS attacks
  10. What is the purpose of the useEffect hook in React?

    • a) To perform side effects in functional components (Correct Answer)
    • b) To manage component state
    • c) To fetch data from an API
    • d) To subscribe to context changes

Comments

Leave a Reply

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

80040