Learn React Js MCQs

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

What is the purpose of `useMemo` hook?

1) To fetch data

2) To manage component state

3) To memoize expensive calculations and avoid unnecessary re-renders

4) To create refs

Answer : Option 3

How do you import a component in React?

1) Using `import` statement

2) Using `require` statement

3) Using `module.exports`

4) Using `include` statement

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 conditionally apply CSS classes in React?

1) Using className prop with ternary operators or logical &&

2) Using style prop

3) Using class attribute

4) Using React.Fragment

Answer : Option 1

What is the purpose of useLayoutEffect hook?

1) To perform side effects after layout updates

2) To manage component state

3) To handle events

4) To fetch data

Answer : Option 1

How do you render a list of items in React?

1) Using Array.map method and returning JSX

2) Using Array.forEach method

3) Using Array.reduce method

4) Using Array.filter method

Answer : Option 1

What does useRef hook return?

1) A ref object with a current property

2) A function

3) A state variable

4) A DOM element

Answer : Option 1

How do you handle asynchronous operations in React?

1) Using useEffect hook with async functions

2) Using useState hook

3) Using useRef hook

4) Using useCallback hook

Answer : Option 1

What is the purpose of componentDidUpdate lifecycle method?

1) To perform actions after the component updates

2) To fetch data

3) To handle events

4) To set initial state

Answer : Option 1

How do you prevent a component from re-rendering in React?

1) Using shouldComponentUpdate lifecycle method or React.memo

2) Using componentDidMount lifecycle method

3) Using useEffect hook

4) Using useRef hook

Answer : Option 1