Learn React Js MCQs

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

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

1) To manage component states

2) To handle events

3) To perform side effects in function components

4) To fetch data

Answer : Option 3

How do you create a functional component in React?

1) By using `React.Component`

2) By using `function` keyword

3) By using `createComponent` method

4) By using `class` keyword

Answer : Option 2

What is the virtual DOM in React?

1) A copy of the real DOM

2) A custom implementation of the DOM

3) A lightweight representation of the real DOM

4) A debugging tool for the DOM

Answer : Option 3

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

1) Using state

2) Using refs

3) Using props

4) Using context

Answer : Option 3

What does JSX stand for?

1) JavaScript XML

2) Java Syntax

3) JavaScript Extension

4) Java Source

Answer : Option 1

How do you conditionally render elements in React?

1) Using `if-else` statements

2) Using `switch-case` statements

3) Using ternary operators or logical &&

4) Using `for` loops

Answer : Option 3

What is the purpose of `React.Fragment`?

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

2) To return multiple elements

3) To render components asynchronously

4) To replace a component

Answer : Option 1

How do you handle forms in React?

1) Using `document.getElementById`

2) Using the `useState` hook

3) Using the `useEffect` hook

4) Using `onSubmit` event

Answer : Option 4

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

1) To style elements

2) To set attributes

3) To uniquely identify elements in a list

4) To bind data

Answer : Option 3

How do you lift state up in React?

1) By using the `useEffect` hook

2) By using the `useContext` hook

3) By moving the state to a common ancestor component

4) By using the `useState` hook

Answer : Option 3