Learn React Js MCQs

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

How do you memoize a callback function in React?

1) Using `useMemo`

2) Using `useEffect`

3) Using `useCallback`

4) Using `useState`

Answer : Option 3

How do you access a component’s state in a class component?

1) Using `this.state`

2) Using `this.props`

3) Using `this.context`

4) Using `this.ref`

Answer : Option 1

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

1) To identify unique elements in a list

2) To manage state

3) To handle side effects

4) To optimize rendering

Answer : Option 1

How do you set default props in a functional component?

1) Using the `useState` hook

2) Using the `defaultProps` property

3) Using default function parameters

4) Using `useEffect`

Answer : Option 3

What is the purpose of the `React.memo` function?

1) To handle side effects

2) To optimize rendering by memoizing a component

3) To create refs

4) To manage state

Answer : Option 2

How do you pass data from child to parent in React?

1) Using `props`

2) Using `context`

3) Using a callback function

4) Using `useState`

Answer : Option 3

What is the purpose of the `useImperativeHandle` hook?

1) To manage state

2) To create refs

3) To customize the instance value that is exposed to parent components when using refs

4) To handle side effects

Answer : Option 3

How do you handle side effects in a functional component?

1) Using `useState`

2) Using `useEffect`

3) Using `useReducer`

4) Using `useRef`

Answer : Option 2

What is the purpose of `React.PureComponent`?

1) To manage state

2) To handle side effects

3) To optimize performance by preventing unnecessary re-renders

4) To create refs

Answer : Option 3

How do you access a DOM element in a functional component?

1) Using `useRef`

2) Using `useState`

3) Using `useEffect`

4) Using `useContext`

Answer : Option 1