ReactJS Q&A

[vc_row][vc_column css_animation=”fadeInLeft”][vc_column_text css=”.vc_custom_1562241367410{background-color: #1e73be !important;}”]

ReactJS Interview Questions & Answers

[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column css_animation=”fadeInLeft” width=”1/2″][vc_tta_accordion][vc_tta_section title=” What are refs in ReactJS?” tab_id=”1562241396480-ab19195b-b830″][vc_column_text]

Refs are used for managing focus, selecting text and triggering animations. It also integrates with third-party libraries. Refs help in getting the reference to a DOM (Document Object Model) node. They return the node that we are referencing. Whenever we need DOM measurements, we can use refs.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is the purpose of render() function in ReactJS?” tab_id=”1562241396498-18d1b017-b527″][vc_column_text]

render() function is used to update the UI. For this, you have to create a new element and send it to ReactDOM.render(). React elements are immutable and once you create an element, you cannot change its attributes. Thus, elements are like a single frame and it depicts the UI at some point. ReactDOM.render() controls the content of the container node you pass and if there is any DOM element already present in it then it would be replaced when first called.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is the use of arrow function in ReactJS?” tab_id=”1562241399901-451790ce-e05c”][vc_column_text]

Arrow functions are extremely important for React operations. It prevents this bugs. Arrow functions make it easier to predict the behavior of this bugs when passed as callbacks. They don’t redefine the value of this within their function body. Hence, prevents bugs caused by the use of this within callbacks.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” How is ReactJS different from angular and VUE js?” tab_id=”1562241400457-c1164bd9-e474″][vc_column_text]Angular Js – developed by Google, angular is a typescript based JavaScript application framework. It is also known as Super-heroic JavaScript MVW Framework. It was developed with the motive to encounter the challenges of creating single page applications. There are several versions of angular such as Angular 2+, Angular 2 or ng2. Angular is the rewritten, mostly incompatible successor to AngularJS which means AngularJS is the oldest framework.

React– React was developed by Facebook in March 2013. It is a JavaScript library that is used for building user interfaces. React creates large web applications and also provides speed, scalability, and simplicity.

Vue Js- Launched in February 2014, Vue is the most famous and rapidly growing framework in JS field. Vue is an intuitive, fast and composable MVVM for building interactive interfaces. It is extremely adaptable and several JavaScript libraries make use of this. Vue is also a web application framework that helps in making advanced single page applications.[/vc_column_text][/vc_tta_section][vc_tta_section title=” How is flux different from redux?” tab_id=”1562241401266-4ab747c2-58fc”][vc_column_text]

Difference Between FLUX and Redux

Flux is a container for application state and logic that are registered to callbacks. Redux is a container for JavaScript apps.
It is an observer pattern that is modified to fit React. It offers interesting features such as writing applications, testing in different environments such as a server, client, etc.
It is a fancy name given to observer pattern and Facebook has developed tools to aid the implementation of these patterns. In redux, actions can be functions or promises.
Flux supports actions that are simple JavaScript objects. Redux is the first choice for web developers because it offers live code editing.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What are the controlled components and uncontrolled components in ReactJS ?” tab_id=”1562241401803-e172f403-d06d”][vc_column_text]Controlled component is more advisable to use as it is easier to implement forms in it. In this, form data are handled by React components. A controlled input accepts values as props and callbacks to change that value.

The uncontrolled component is a substitute for controlled components. Here form data is handled by DOM itself. In uncomfortable components, the ref can be used to get the form values from DOM.[/vc_column_text][/vc_tta_section][vc_tta_section title=” Explain the difference between functional and class components.” tab_id=”1562241402402-f544c40f-38ba”][vc_column_text]Functional components are those components that returns React elements as a result. These are just simple old JavaScript functions. React 0.14 has given a new shortcut for creating simple stateless components that are known as functional components. These components make use of easy JavaScript functions.

Class components – most of the tech-savvy people are more familiar with class components as they have been around the corner for a longer time. These components make use of plain old java objects for creating pages, mixins, etc in an identical way. Using React’s create a class factory method, a literal is passed in defining the methods of a new component.[/vc_column_text][/vc_tta_section][vc_tta_section title=” What do you understand by mixin or higher order components in ReactJs ?” tab_id=”1562241402962-7a9a8833-fe28″][vc_column_text]

Higher order components (HOC) is a function that takes component as well as returns a component. It is a modern technique in React that reuses the component logic. However, Higher order components are not a part of React API, per se. These are patterns that emerge from React’s compositional nature. In other words, HOC’s are functions that loop over and applies a function to every element in an array.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are Synthetic events?” tab_id=”1562241403602-fe238b86-64a0″][vc_column_text]SyntheticEvent is a cross-browser wrapper around browser’s native event. In React all of your event handlers will be passed instances of SyntheticEvent.The synthetic event works the same way as the event system of browsers, the only difference is that the same code will work across all browsers.

Below is a simple example of how to listen for a click event in react

import React, { Component } from 'react';
class ShowAlert extends Component {
  showAlert() {
    alert("Im an alert");
  render() {
    return (
      <button onClick={this.showAlert}>show alert </button>
export default ShowAlert;

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is the difference between Dom and virtual Dom in ReactJS ?” tab_id=”1562241404324-b22a2330-e10a”][vc_column_text]DOM is the acronym for Document Object Model. Dom is also called HTML DOM as it is an abstraction of structured code called HTML for web developers. Dom and HTML code are interrelated as the elements of HTML are known as nodes of DOM. It defines a  structure where users can create, alter, modify documents and the content present in it. So while HTML is a text, DOM is an in-memory representation of this text.

Virtual DOM is an abstraction of abstraction as it has been derived from HTML DOM. It is a representation of DOM objects like a lightweight copy. The virtual DOM was not invented by React, it is only used and provided for free.[/vc_column_text][/vc_tta_section][vc_tta_section title=” Enlist the advantages and disadvantages of ReactJS ?” tab_id=”1562241404979-caa2ad7d-2d16″][vc_column_text]React.js is used by web developers for creating large web pages without reloading the entire page. It uses the data and can be changed over time.

The following are the advantages of using React.js-

1- React makes Search engine optimization (SEO)  easy.

2- It is very efficient as it ensures readability and easy maintenance.

3- It gives extraordinary developer tools to web developers and makes Java coding easier for them.

4- UI test cases.

The following are the disadvantages of React-

1- Some major configurations are required for integrating React js with traditional MVC framework such as substituting erb with React js.

2- It is a steep learning process for people who are new to web development world.[/vc_column_text][/vc_tta_section][/vc_tta_accordion][/vc_column][vc_column css_animation=”fadeInRight” width=”1/2″][vc_tta_accordion color=”peacoc” active_section=”1″][vc_tta_section title=” What is ReactJS ?” tab_id=”1562241419293-6e6a3ea0-60c5″][vc_column_text]

React js is javascript based UI Library developed at Facebook, to create an interactive, stateful & reusable UI components. It is one of the most popular javascript frameworks that is created for handling the presentation layer for the web and mobile apps.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” List some advantages of ReactJS ?” tab_id=”1562241419309-87b42477-7db5″][vc_column_text]

Advantages of React Js

  • React.js is extremely efficient: React.js creates its own virtual DOM where your components actually live. This approach gives you enormous flexibility and amazing gain in performance. React.js also calculates what are the changes needed to be made in DOM. This process of React.js avoids expensive DOM operations and make updates in a very client manner.
  • It makes writing Javascript easier: React.js uses a special syntax called JSX, which allows you to mix HTML with Javascript. The user can drop a bit of HTML in the render function without having to concatenate strings, this is another fantastic thing. React.js turns those bits of HTML into functions with a special JSXTransformer.
  • It gives you out-of-the-box developer tools: When you start your journey with React.js, do not forget to install official React.js chrome extension. It makes debugging your application much easier. After you install the extension, you will have a direct look into the virtual DOM as if you were browsing a regular DOM tree in the elements panel. Isn’t it pretty amazing!
  • It’s awesome for SEO: One of the biggest problems with other Javascript frameworks is that they do not search engine friendly. Though there have been some improvements in this area, search engines generally have trouble reading Javascript heavy applications. React.js stands out from the crowd because you can run React.js on the server, and the virtual DOM will be rendered to the browser as a regular web page.
  • UI Test Cases: It is extremely easy to write UI test cases because the virtual DOM system implemented entirely in JS.

Source:[/vc_column_text][/vc_tta_section][vc_tta_section title=” What are Components in ReactJS ?” tab_id=”1562241443692-488448d3-cc4d”][vc_column_text]React Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.

Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

Below is ample component written in ES6 class to display a welcome message on the screen.

class Welcome extends React.Component {
  render() {
    return <h1>Hello, {} </h1>;

const element = <Welcome name="Sara" />;

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is JSX?” tab_id=”1562241444317-8df2106f-db67″][vc_column_text]JSX is an XML/HTML-like syntax used by React that extends ECMAScript so that XML/HTML-like text can co-exist with JavaScript/React code. The syntax is intended to be used by preprocessors (i.e., transpilers like Babel) to transform HTML-like text found in JavaScript files into standard JavaScript objects that a JavaScript engine will parse.

Basically, by using JSX you can write concise HTML/XML-like structures (e.g., DOM like tree structures) in the same file as you write JavaScript code, then Babel will transform these expressions into actual JavaScript code. Unlike the past, instead of putting JavaScript into HTML, JSX allows us to put HTML into JavaScript.

By using JSX one can write the following JSX/JavaScript code:

var nav = (
    <ul id="nav">
      <li><a href="#">Home</li>
      <li><a href="#">About

<li><a href=”#”>Clients

<li><a href=”#”>Contact Us

</ul> );

And Babel will transform it into this:

var nav = React.createElement(
   { id: "nav" },
         { href: "#" },
         { href: "#" },
         { href: "#" },
         { href: "#" },
         "Contact Us"

[/vc_column_text][/vc_tta_section][vc_tta_section title=” Explain life Cycle of React JS Component ?” tab_id=”1562241444873-40dbcf19-dd6d”][vc_column_text]

React JS Component Lifecycle

Each component has several “lifecycle methods” that you can override to run code at particular times in the process. Methods prefixed with will are called right before something happens, and methods prefixed with did are called right after something happens.


These methods are called when an instance of a component is being created and inserted into the DOM:

  • constructor()
  • componentWillMount()
  • render()
  • componentDidMount()


An update can be caused by changes to props or state. These methods are called when a component is being re-


  • componentWillReceiveProps()
  • shouldComponentUpdate()
  • componentWillUpdate()
  • render()
  • componentDidUpdate()


This method is called when a component is being removed from the DOM:

  • componentWillUnmount()

Other APIs

Each component also provides some other APIs:

  • setState()
  • forceUpdate()

Class Properties

  • defaultProps
  • displayName

Instance Properties

  • props
  • state

[/vc_column_text][/vc_tta_section][vc_tta_section title=” List some features of ReactJS ?” tab_id=”1562241445766-4bc5e02f-4e6e”][vc_column_text]Undoubtedly today React is among of one the best JavaScript UI frameworks. It comes with a lot of features that helps programmers to create beautiful application easily, we have listed some of them below.

  • It’s Adaptability
  • Free and Open Source
  • Decorators from ES7
  • Server-side Communication
  • Asynchronous Functions & Generators
  • Flux Library
  • Destructuring Assignments
  • Usefulness of JSX

[/vc_column_text][/vc_tta_section][vc_tta_section title=” How to use Events in ReactJS ?” tab_id=”1562241446337-7e45e31e-d624″][vc_column_text]Using Events is React js is very similar to handling event on DOM elements.The difference is only in syntax like.

  1. The name of event is React js is always in camelCase.
  2. With JSX you pass a function as the event handler, rather than a string.

Lets understand by an example:

// In HTML
<button onclick="activateAccount()">
  Activate Account
//In React
<button onClick={activateAccount}>
  Activate Account

Another difference is that in React js you cannot return false to prevent default behavior in React. You must call preventDefault explicitly.[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is flux in JavaScript?” tab_id=”1562241446906-3db79f5b-5f21″][vc_column_text]Flux is an application architecture for creating data layers in JavaScript applications.It was designed at Facebook along with the React view library.Flux is not a framework or a library. It is simply a new kind of architecture that complements React and the concept of Unidirectional Data Flow.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are refs in ReactJs ? When to use it.” tab_id=”1562241447557-bf2fb874-42e3″][vc_column_text]In React ref is used to store the reference of element or component returned by the component render() configuration function.Refs should be avoided in most cases, however, they can be useful when we need DOM measurements or to add methods to the components.

Refs can be used in the following cases

  • Managing focus, text selection, or media playback.
  • Triggering imperative animations.
  • Integrating with third-party DOM libraries.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What are stateless components in ReactJS?” tab_id=”1562241448173-51986548-2fde”][vc_column_text]Stateless components are components that don’t have any state. When something is stateless, it calculates its internal state but it never directly mutates it.For creating a stateless components No class and this keyword is needed.You can create a stateless components using plain functions or Es6 arrow function. Below is an example of stateless component in react.

//In Es6 
const Pane = (props) =>


//In Es5 
const Username = ({ username }) =>

The logged in user is: {username}[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is the difference between State and props in React Js ?” tab_id=”1562241448810-01419b2f-2c7d”][vc_column_text]Props are shorthand for properties.they are very similar to an argument is passed to a pure javascript function. Props of the component are passed from parent component which invokes component. During a component’s life cycle props should not change consider them as immutable.In React all props can be accessible with this.props.

import React from 'react';
class Welcome extends React.Component {
  render() {
    return <h1>Hello {}</h1>;
const element = ;

State are used to create dynamic and interactive components in React.State is heart of react component that makes it alive and determines how a component renders & behaves.

// simple state example 
import React from 'react';
class Button extends React.Component {
  constructor() {
    this.state = {
      count: 0,

  updateCount() {
    this.setState((prevState, props) => {
      return { count: prevState.count + 1 }

  render() {
    return (<button
              onClick={() => this.updateCount()}
              Clicked {this.state.count} times

export default Button;


WhatsApp us