Add office photos
Engaged Employer

Cognizant

3.8
based on 48.6k Reviews
Proud winner of ABECA 2024 - AmbitionBox Employee Choice Awards
Filter interviews by

TCS Interview Questions and Answers

Updated 5 Feb 2024
Popular Designations

Q1. How do you avoid re-rendering of a component? With useEffect second parameter, should ComponentUpdate

Ans.

To avoid re-rendering, use shouldComponentUpdate or React.memo

  • Use shouldComponentUpdate to compare current and next props/state

  • Use React.memo to memoize functional components

  • Use useMemo to memoize expensive computations

  • Use useCallback to memoize event handlers

  • Use PureComponent for class components

Add your answer

Q2. What are refs? How will you use it for getting input value? Explain with code.

Ans.

Refs are a way to access DOM nodes or React components directly. They can be used to get input values.

  • Refs provide a way to access DOM nodes or React components directly.

  • They are commonly used to get input values or trigger imperative animations.

  • Refs can be created using the `createRef()` method or by using a callback function.

  • To get the value of an input using refs, you can assign a ref to the input element and access its value property.

View 1 answer

Q3. What are the ways to handle Errors in React?

Ans.

Error handling in React can be done using try-catch blocks, error boundaries, and handling asynchronous errors.

  • Use try-catch blocks to handle synchronous errors

  • Use error boundaries to catch errors in child components

  • Handle asynchronous errors using promises or async/await

  • Use third-party libraries like Sentry or Bugsnag for better error tracking

  • Display user-friendly error messages to improve user experience

View 1 answer

Q4. What is Lazy Loading, Suspense. How do they work?

Ans.

Lazy Loading and Suspense are techniques used to improve performance by loading components and data only when needed.

  • Lazy Loading delays the loading of non-critical resources until they are needed, reducing initial load time.

  • Suspense allows components to wait for data to load before rendering, improving user experience.

  • Lazy Loading and Suspense can be used together to optimize performance and user experience.

  • Example: A website with a large image gallery can use Lazy Loading t...read more

Add your answer
Discover TCS interview dos and don'ts from real experiences

Q5. How componentWillUnmount works?

Ans.

componentWillUnmount is a lifecycle method in React that is called right before a component is unmounted and destroyed.

  • componentWillUnmount is used to perform any necessary cleanup tasks before a component is removed from the DOM.

  • It is commonly used to cancel any pending network requests, remove event listeners, or clear timers or intervals.

  • The method is called automatically by React when a component is about to be unmounted.

  • It is important to clean up any resources or subscr...read more

View 1 answer

Q6. Explain useState, useEffect Hooks.

Ans.

useState and useEffect are React Hooks used for managing state and side effects respectively.

  • useState is used to manage state in functional components

  • It returns an array with two elements - the current state value and a function to update the state

  • useEffect is used to manage side effects like fetching data or updating the DOM

  • It takes a function as its argument and runs it after every render

  • useEffect can also take a second argument which is an array of dependencies to control ...read more

Add your answer

More about working at Cognizant

Top Rated Mega Company - 2024
Top Rated IT/ITES Company - 2024
HQ - Teaneck. New Jersey., United States (USA)
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top React Developer Interview Questions from Similar Companies

3.4
 • 17 Interview Questions
3.8
 • 15 Interview Questions
3.5
 • 12 Interview Questions
View all
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter