Learn React Js MCQs

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

What is the purpose of `propTypes` in React?

1) To define component styles

2) To define initial state

3) To type-check props passed to components

4) To render components conditionally

Answer : Option 3

How do you manage global state in a React application?

1) Using `useEffect` hook

2) Using `React.memo`

3) Using `Context API` or state management libraries like Redux

4) Using `localStorage`

Answer : Option 3

What does `useEffect` return?

1) A cleanup function

2) An array of dependencies

3) An event listener

4) A DOM element

Answer : Option 1

How do you create a ref in React?

1) Using `useRef` hook

2) Using `useState` hook

3) Using `createRef` method

4) Using `useContext` hook

Answer : Option 1

What is the purpose of `React.StrictMode`?

1) To enable concurrent mode

2) To check for potential problems in the application

3) To improve performance

4) To handle side effects

Answer : Option 2

How do you create a context in React?

1) Using `createContext` method

2) Using `useState` hook

3) Using `useEffect` hook

4) Using `React.createClass`

Answer : Option 1

What is the purpose of `componentDidMount` lifecycle method?

1) To handle events

2) To fetch data

3) To perform actions after the component has been rendered

4) To set initial state

Answer : Option 3

How do you style components in React?

1) Using `CSS` files

2) Using `styled-components` library

3) Using `inline styles`

4) All of the above

Answer : Option 4

What does `shouldComponentUpdate` return?

1) A DOM node

2) A new state

3) A boolean value to decide whether the component should update

4) An event handler

Answer : Option 3

How do you create a higher-order component (HOC) in React?

1) Using `createElement` method

2) Using `React.memo`

3) By wrapping a component in another component

4) Using `useEffect` hook

Answer : Option 3