React Interview Questions

What is React?
  • React is a front-end JavaScript library developed by Facebook in 2011.
  • It follows the component based approach which helps in building reusable UI components.
  • It is used for developing complex and interactive web and mobile UI.
  • Even though it was open-sourced only in 2015, it has one of the largest communities supporting it.
What are the features of React?
Major features of React are listed below:
  • It uses the virtual DOM instead of the real DOM.
  • It uses server-side rendering.
  • It follows uni-directional data flow or data binding.
What is Props?
Props is the shorthand for Properties in React. They are read-only components which must be kept pure i.e. immutable. They are always passed down from the parent to the child components throughout the application. A child component can never send a prop back to the parent component. This help in maintaining the unidirectional data flow and are generally used to render the dynamically generated data.
What are the different phases of React component’s lifecycle?
There are three different phases of React component’s lifecycle:
  • Initial Rendering Phase: This is the phase when the component is about to start its life journey and make its way to the DOM.
  • Updating Phase: Once the component gets added to the DOM, it can potentially update and re-render only when a prop or state change occurs. That happens only in this phase.
  • Unmounting Phase: This is the final phase of a component’s life cycle in which the component is destroyed and removed from the DOM.
What do you know about controlled and uncontrolled components?
Controlled Components Uncontrolled Components
They do not maintain their own state. They maintain their own state.
Data is controlled by the parent component. Data is controlled by the DOM
They take in the current values through props and then notify the changes via callbacks. Refs are used to get their current values