Learn React Js MCQs

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

What is the purpose of the `componentDidMount` lifecycle method?

1) To manage state updates

2) To perform actions after the component has been rendered

3) To handle side effects

4) To render JSX

Answer : Option 2

How do you create a context in React?

1) Using `React.createContext`

2) Using `useState`

3) Using `useReducer`

4) Using `React.Fragment`

Answer : Option 1

What does the `useRef` hook return?

1) A state and setState function

2) An array of dependencies

3) A context object

4) A ref object with a `current` property

Answer : Option 4

How do you optimize a React component for performance?

1) Using `React.memo`

2) Using `props` directly

3) Using inline styles

4) Using `setState` in `componentDidMount`

Answer : Option 1

What is the purpose of the `useCallback` hook?

1) To manage side effects

2) To memoize callback functions and prevent unnecessary re-renders

3) To handle state updates

4) To create a new context

Answer : Option 2

What is the purpose of the `useReducer` hook?

1) To manage more complex state logic

2) To create refs

3) To fetch data from an API

4) To handle side effects

Answer : Option 1

How do you create a functional component in React?

1) By extending `React.Component`

2) By using the `useState` hook

3) By using the `useEffect` hook

4) By creating a function that returns JSX

Answer : Option 4

What does the `useState` hook do?

1) Creates a new context

2) Manages state in functional components

3) Creates a ref

4) Handles side effects

Answer : Option 2

How do you pass props to a component?

1) By adding attributes to the JSX tag

2) By using `this.props`

3) By using `setState`

4) By using `useEffect`

Answer : Option 1

What is the purpose of the `useEffect` hook?

1) To manage component state

2) To render JSX

3) To handle side effects in functional components

4) To create refs

Answer : Option 3