? React MCQ 2025
? React MCQ 2025
1. What is React?
A) A database
B) A backend framework
C) A JavaScript library for building UIs
D) A CSS preprocessor
Answer: C
Note: React is a library developed by Facebook for building user interfaces.
3. What is JSX?
A) A templating engine
B) An XML parser
C) JavaScript syntax extension
D) A CSS framework
Answer: C
Note: JSX allows writing HTML-like syntax inside JavaScript.
34. What’s the correct way to pass a prop named title to a component?
A) <Component :title="text" />
B) <Component {title} />
C) <Component title="text" />
D) <Component title:text />
Answer: C
Note: Props are passed as HTML attributes in JSX.
38. Which of the following can hold both state and props?
A) Functional components
B) Only class components
C) JSX
D) Hooks
Answer: A
Note: With hooks, functional components can hold both state and props.
47. Which hook allows you to track previous props or state values?
A) useEffect
B) useMemo
C) useCallback
D) useRef
Answer: D
Note: useRef can store the previous value across renders.
55. What’s the best hook for form field value management?
A) useEffect
B) useRef
C) useState
D) useContext
Answer: C
Note: useState is best for tracking and updating form values.
58. Which hook is used for shared state across multiple components?
A) useState
B) useRef
C) useEffect
D) useContext
Answer: D
Note: useContext allows you to access context values in child components.
69. How can you group multiple inputs under one state?
A) Use useEffect
B) Use useReducer or an object in useState
C) Use multiple useState
D) It’s not possible
Answer: B
Note: Group fields in an object or manage them with useReducer.
82. Which component wraps the entire application for enabling routing?
A) <Switch>
B) <Route>
C) <BrowserRouter>
D) <RouterPath>
Answer: C
Note: <BrowserRouter> is the top-level component that enables routing.
86. Which hook gives you access to the current location object?
A) usePath
B) useRoute
C) useLocation
D) useParams
Answer: C
Note: useLocation returns information about the current URL.
88. Which component renders the first matching route among children?
A) <BrowserRouter>
B) <Navigate>
C) <Switch>
D) <Routes>
Answer: D
Note: In v6, <Routes> replaces <Switch> and only renders the first match.
99. What happens if two <Route> paths match the same path?
A) Both render
B) Only the first renders
C) None render
D) It throws an error
Answer: B (in <Routes>)
Note: <Routes> renders only the first matching route.
122. Which hook gives you direct access to the Redux store?
A) useStore()
B) useRedux()
C) useSelector()
D) useReducer()
Answer: A
Note: useStore() returns the Redux store instance.
123. What is the recommended structure for Redux Toolkit slice files?
A) One for each reducer
B) All actions in one file
C) Slices that group actions + reducers
D) Separate folders per action
Answer: C
Note: RTK encourages the slice-based modular structure.
128. Which React component makes the Redux store available to all components?
A) <Router>
B) <App>
C) <Provider>
D) <Connect>
Answer: C
Note: The <Provider> component wraps the app to pass down the Redux store.
137. Which hook is often used in Redux-like state management with Context API?
A) useMemo()
B) useEffect()
C) useReducer()
D) useSelector()
Answer: C
Note: useReducer() mimics Redux logic in functional components.
139. What is the main advantage of Redux Toolkit over vanilla Redux?
A) It works with Vue
B) It makes Redux async
C) Reduces boilerplate code
D) Removes reducer logic
Answer: C
Note: RTK simplifies Redux with built-in helpers and best practices.
147. Which two hooks are primarily used for custom context logic?
A) useState & useEffect
B) useReducer & useContext
C) useRef & useMemo
D) useLayoutEffect & useDebugValue
Answer: B
Note: useContext for consuming and useReducer for managing logic.
151. Which hook is used to customize how a hook is displayed in React DevTools?
A) useMemo()
B) useRef()
C) useDebugValue()
D) useLayoutEffect()
Answer: C
Note: useDebugValue() lets you show custom labels in DevTools.
171. Which React hook is most suitable for authentication state logic?
A) useState()
B) useContext()
C) useRef()
D) useEffect()
Answer: B
Note: Context API helps manage global state like user auth.
180. Can you memoize a component with React.memo() and still use hooks?
A) No
B) Only with classes
C) Yes
D) Only with useEffect
Answer: C
Note: Functional components with hooks can be memoized.
182. What tool is commonly used for unit testing React components?
A) Webpack
B) Mocha
C) Jest
D) Babel
Answer: C
Note: Jest is the most popular test runner for React apps.
185. Which lifecycle method is ideal for logging errors in class components?
A) componentDidMount()
B) getDerivedStateFromProps()
C) componentDidCatch()
D) render()
Answer: C
Note: Used in Error Boundaries to catch runtime errors.
197. What command starts a React app created by CRA (Create React App)?
A) npm run dev
B) npm start
C) npm react
D) npm serve
Answer: B
Note: npm start runs the app in development mode.