Learn React Js MCQs

Prepare React Js MCQs (Multiple choice Questions) for exam and job interviews.

What is the purpose of useMemo hook?

1) To memoize expensive calculations and optimize performance

2) To manage state

3) To create refs

4) To handle events

Answer : Option 1

How do you handle forms in React?

1) Using controlled components with useState hook

2) Using uncontrolled components with refs

3) Using context API

4) Using useEffect hook

Answer : Option 1

What is React.Fragment used for?

1) To group multiple elements without adding extra nodes to the DOM

2) To manage state

3) To handle side effects

4) To create context

Answer : Option 1

How do you manage global state in React?

1) Using Context API or state management libraries like Redux

2) Using useState hook

3) Using useEffect hook

4) Using localStorage

Answer : Option 1

What is the primary purpose of the `useContext` hook in React?

1) To handle side effects

2) To manage component state

3) To access values from a Context object

4) To create refs

Answer : Option 3

How do you pass data from a parent component to a child component?

1) Via props

2) Via context

3) Via state

4) Via refs

Answer : Option 1

What is the purpose of the `key` prop in React?

1) To manage state

2) To bind the event handler

3) To give each element a stable identity

4) To set the component ID

Answer : Option 3

How do you optimize a React app for performance?

1) Using `React.memo`, `useCallback`, and `useMemo`

2) Using `setState` directly

3) Using `componentDidMount`

4) Using inline functions

Answer : Option 1

What does the `useReducer` hook return?

1) A context object

2) A function and a ref

3) A state and a setState function

4) A state and a dispatch function

Answer : Option 4

How do you import React in a JavaScript file?

1) import ReactJS from "react"

2) require("React")

3) import React from "react"

4) import { React } from "react"

Answer : Option 3