-
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
-
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
-
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
-
Which of the following is NOT a valid lifecycle method in React?
- a) componentWillMount
- b) componentWillUpdate
- c) componentWillReceiveProps
- d) componentWillUnmount (Correct Answer)
-
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
-
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
-
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)
-
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)
-
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
-
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