MCQ Quiz
What is the primary purpose of React?
A) To handle HTTP requests
B) To manage application state
C) To build user interfaces
D) To manage databases
What does JSX stand for?
A) JavaScript XML
B) Java Syntax Extension
C) JavaScript Extension
D) JavaScript XSLT
Which of the following is a way to create a React component?
A) Using a class
B) Using a function
C) Both A and B
D) Neither A nor B
What is the purpose of the useState hook?
A) To handle side effects
B) To manage component state
C) To manage component lifecycle
D) To handle routing
Which of the following is a valid way to import a component in React?
A) import { Component } from 'react'
B) import Component from 'react'
C) import 'react/Component'
D) import [ Component ] from 'react'
What is the virtual DOM in React?
A) A representation of the real DOM
B) A separate DOM used for testing
C) A part of the HTML specification
D) A new type of DOM element
Which method is used to handle side effects in function components?
A) useState
B) useEffect
C) useContext
D) useReducer
What is the purpose of props in React?
A) To manage component state
B) To pass data between components
C) To handle component lifecycle
D) To manage side effects
Which of the following is not a valid lifecycle method in React?
A) componentDidMount
B) componentWillReceiveProps
C) componentDidUpdate
D) componentWillUnmount
How do you create a context in React?
A) React.createContext()
B) React.createContext
C) React.newContext()
D) React.newContext
What is the purpose of the key prop in React?
A) To uniquely identify elements
B) To manage component state
C) To handle side effects
D) To manage routing
Which command is used to create a new React app?
A) npm create-react-app
B) npx create-react-app
C) react-init
D) npx init-react-app
What is the use of the useContext hook in React?
A) To manage component state
B) To handle side effects
C) To use context API
D) To manage routing
What is the purpose of the React.Fragment component?
A) To wrap multiple elements without adding extra nodes to the DOM
B) To manage component state
C) To handle side effects
D) To manage routing
What is the difference between state and props in React?
A) State is mutable, props are immutable
B) State is immutable, props are mutable
C) Both are immutable
D) Both are mutable
Which of the following is used to pass data to a component from outside in React?
A) props
B) state
C) context
D) ref
What is the purpose of the useReducer hook in React?
A) To manage complex state logic
B) To handle side effects
C) To manage routing
D) To use context API
Which of the following is a common way to handle forms in React?
A) Using controlled components
B) Using uncontrolled components
C) Both A and B
D) Neither A nor B
What is the purpose of the useRef hook in React?
A) To manage component state
B) To access DOM elements directly
C) To handle side effects
D) To manage routing
Which method is used to update the state in React?
A) this.setState()
B) this.updateState()
C) this.changeState()
D) this.modifyState()
What is the purpose of the render method in React class components?
A) To render the component to the DOM
B) To manage component state
C) To handle side effects
D) To manage routing
Which of the following is a way to create a functional component in React?
A) function MyComponent() {}
B) const MyComponent = () => {}
C) Both A and B
D) Neither A nor B
What is the primary purpose of React Router?
A) To manage global state
B) To handle HTTP requests
C) To manage navigation and routing
D) To handle form submissions
Which of the following is a valid way to handle events in React?
A) Using event listeners
B) Using event handlers
C) Using JavaScript functions
D) Using HTML event attributes
What is the use of the useMemo hook in React?
A) To memoize values
B) To handle side effects
C) To manage routing
D) To use context API
Which of the following is a way to fetch data in React?
A) Using the fetch API
B) Using axios
C) Both A and B
D) Neither A nor B
What is the purpose of the useCallback hook in React?
A) To memoize callback functions
B) To handle side effects
C) To manage routing
D) To use context API
What is the use of the useImperativeHandle hook in React?
A) To customize the instance value
B) To handle side effects
C) To manage routing
D) To use context API
Which of the following is not a valid hook in React?
A) useState
B) useEffect
C) useClass
D) useRef
What is the purpose of the useLayoutEffect hook in React?
A) To handle side effects that require DOM updates
B) To manage component state
C) To manage routing
D) To use context API