Learn React Js MCQs

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

What does the `useState` hook return?

1) An array with the current state and a function to update it

2) An object with the state

3) A function to get the state

4) A string representation of the state

Answer : Option 1

How do you handle events in React?

1) By passing functions to the event handlers

2) By using inline event handling

3) By using global event listeners

4) By using state

Answer : Option 1

What is the purpose of `React.Fragment`?

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

2) To manage state

3) To handle side effects

4) To create refs

Answer : Option 1

How can you manage global state in React?

1) By using Context API or Redux

2) By using local state only

3) By using props only

4) By using refs only

Answer : Option 1

What does `componentWillUnmount` do?

1) Runs code before a component is removed from the DOM

2) Runs code after a component mounts

3) Runs code during rendering

4) Runs code during state updates

Answer : Option 1

How do you fetch data in a functional component?

1) By using `useEffect` with fetch API

2) By using constructor

3) By using lifecycle methods

4) By using state

Answer : Option 1

What is the use of `key` prop in lists?

1) To help React identify which items have changed

2) To manage state

3) To handle events

4) To create refs

Answer : Option 1

How do you create a controlled component?

1) By setting the value of an input to state and updating it on change

2) By using default values

3) By using refs

4) By using props

Answer : Option 1

What is the purpose of `React.lazy`?

1) To enable lazy loading of components

2) To manage state

3) To handle side effects

4) To create refs

Answer : Option 1

How do you create a custom hook?

1) By defining a function that uses React hooks

2) By using lifecycle methods

3) By creating a class component

4) By using context

Answer : Option 1