Learn React Js MCQs

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

What is the purpose of `useCallback` hook?

1) To manage side effects

2) To memoize functions and prevent unnecessary re-renders

3) To manage state

4) To create refs

Answer : Option 2

How do you add event listeners in React?

1) Using `addEventListener`

2) Using `document.getElementById`

3) Using `on<EventName>` props

4) Using `window.addEventListener`

Answer : Option 3

What is the purpose of `React.memo`?

1) To manage component state

2) To create a class component

3) To optimize performance by memoizing functional components

4) To create refs

Answer : Option 3

How do you perform side effects in a React function component?

1) Using `useState` hook

2) Using `useMemo` hook

3) Using `useEffect` hook

4) Using `useRef` hook

Answer : Option 3

What does `useState` hook accept as an argument?

1) A function

2) A number

3) An initial state value

4) A boolean

Answer : Option 3

How do you update the state in a React class component?

1) Using `setState` method

2) Using `useState` hook

3) Using `forceUpdate` method

4) Using `updateState` method

Answer : Option 1

What is the purpose of `React.Children` utility?

1) To create new child components

2) To clone child elements

3) To work with and manipulate the children passed to a component

4) To manage state

Answer : Option 3

How do you access props in a React functional component?

1) Using `this.props`

2) Using `useEffect` hook

3) Using `props` argument

4) Using `useState` hook

Answer : Option 3

What is the purpose of `defaultProps` in React?

1) To set default values for props

2) To define prop types

3) To manage state

4) To handle side effects

Answer : Option 1

How do you pass data between sibling components in React?

1) Using state

2) Using refs

3) By lifting state up to a common parent

4) Using context

Answer : Option 3