Learn React Js MCQs

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

How do you create a context in React?

1) Using `useState`

2) Using `React.createContext`

3) Using `useRef`

4) Using `useReducer`

Answer : Option 2

What is the purpose of the `useTransition` hook?

1) To create refs

2) To manage state

3) To defer rendering a non-urgent update

4) To handle side effects

Answer : Option 3

How do you handle user inputs in React?

1) Using `useRef`

2) Using `controlled components`

3) Using `useEffect`

4) Using `useState`

Answer : Option 2

What is the purpose of `useDeferredValue`?

1) To handle side effects

2) To defer updating a value until after a higher priority update

3) To create a new context

4) To optimize performance

Answer : Option 2

How do you handle errors in React components?

1) Using `try-catch` in `render`

2) Using `Error Boundaries`

3) Using `useState`

4) Using `useEffect`

Answer : Option 2

What is the purpose of the `useMemo` hook in React?

1) To manage state

2) To optimize rendering by memoizing a value

3) To handle side effects

4) To create refs

Answer : Option 2

How do you pass data between siblings in React?

1) Using `props`

2) Using `context`

3) Using a parent component

4) Using `useState`

Answer : Option 3

What is the purpose of `React.StrictMode`?

1) To manage state

2) To optimize performance

3) To identify potential problems in the application

4) To handle side effects

Answer : Option 3

How do you handle conditional rendering in React?

1) Using `useState`

2) Using `useEffect`

3) Using `if-else` or ternary operators

4) Using `useContext`

Answer : Option 3

What is the purpose of `useRef` in React?

1) To create a mutable object that persists across renders

2) To manage state

3) To handle side effects

4) To optimize rendering

Answer : Option 1