Request a Call back

    React Interview Questions

    Frequently Asked Interview Questions And Answers For React Freshers

    What is React?

    React may be a library for serving to developers build user interfaces (UIs) as a tree of little items referred to as parts.

    What Are The Major Features of React?

    The major features of React are:
    o React uses Virtual DOM instead of RealDOM because it considers that RealDOM manipulations are expensive then it.
    o It Supports server-side rendering.
    o It Follows Unidirectional* data flow or data binding.
    o It Uses reusable/composable UI components to develop the view.

    What is JSX In React?

    JSX is the syntax extention to the javascript,it gives the syntactinc elements to the React.createElement() function andhelpsus to code like HTML type template like syntax.
    In the example below text inside

    tag return as JavaScript function to the render function.
    class App extends React.Component {
    render() {

    {‘Welcome to Tops Technologies!’}


    How To Create Components in React?

    There are two possible ways to create a component.
    i. Function Components: one of the simplest way to create a component is to use javascript functions that accepts props as first parameter and returns React element:
    ii. Function Greeting({ message }) {
    iii. Return

    {`Hello user, ${message}`}

    iv. Class Components: We can use ES6 class to define the component.The above function component can be written as:
    v. Class Greeting extends React.Component {
    vi. render() {
    vii. return

    {`Hello user, ${this.props.message}`}

    viii. }

    When To Use A Class Component Over a Function Component In React?

    When the component needs the lifecycle methods then use class Component otherwise we can use function component.

    What Are Pure Components In React?

    React.Pure Component and React.Component both are same just shouldComponentUpdate()method is handled by the pure component the time when the props state changed the pure component compares both props and state, while on another hand the auto rendering will occur.

    What Are Props in React?

    The input given to the components are the props. That are the single values that are given to the components on the creation time using a naming convention similar to HTML tag attributes.
    The primary purpose of props in React is to provide the following component functionality:
    . Pass custom data to your component.
    i. Trigger state changes.
    ii. Use via this.props.reactProp inside component’s render() method.
    For example, let us create an element with reactProp property:

    This reacts,.Prop()method or the name that you give to the method becomes a property attached to React’s native props object and it originally exists on all components created using the React library.

    What Is The Difference Between State and Props In React?

    Props and State are both javascript objects holding the information of the output created by rendering, but they are different in functionality with the components.
    Props are passed to the components by function type while the state is managed within components similar to variables declared in the function.

    Why Should We Not Update The State Directly?

    We can’t auto-render the content by updating states.
    this.state.message = ‘Hello tops!’
    We have to use setState instead of this method, this method schedules an update in components’ object when the state changes it sends the response by re-rendering.
    this.setState({ message: ‘Hello World’ })
    Note: You can directly assign to the state object either in the constructor or using the latest javascript’s class field declaration syntax.

    What Is The Purpose Of Callback Function As an Argument of SetState() In React?

    When the setState function is invoked the call back function is used after the component is rendered.
    Note: It is recommended to use lifecycle method rather than this callback function.
    setState({ name: ‘Ramesh’ }, () => console.log(‘The name has updated and component re-rendered’))

    How To Pass A Parameter To An Event Handler or Callback In React?

    We can use arrow function to wrap en event handler into function and pass parameter.

    What Are Synthetic Events in React?

    Synthetic Event is for a cross-browser wrapper around the browser’s native has the same API as the browser’s native event.
    StopPropagation() and preventDefault() are different except all methods work across all browsers.

    What Are "Key" Props In React And What is The Benefit of Using Them in Arrays of Elements?

    A Key is a string that is included while creating the array, it is helpful for keeping track of what is added or what is changed or removed.
    Most often we use IDs from our data as keys:
    const todoItems = =>

    • {todo.text}

    When you don’t have stable IDs for rendered items, you may use the item index as a key as a last resort:
    const todoItems =, index) =>

    • {todo.text}


    What Is the Use of Refs In React?

    We can use the ref to return a reference to the element. It is much helpful in the case of need for direct access of DOM element or instance of the component.

    What is Virtual DOM In React?

    Virtual DOM means the in-memory representation of the Real DOM. The Real DOM contains the representation of the UI that is kept in the memory.
    This process happened in between the render function’s call and the displaying elements on the screen. This method is called reconciliation.

    How Virtual DOM Works In React?

    It works in three ways, these are following.
    i. When any data in the program changes the entire UI is re-rendered in Virtual DOM representation.
    ii. The calculation of the difference between the old DOM and the new one is done after that.
    iii. When eh changes are done on the Real DOM it will change only the things that have been changed.

    What Is The Difference Between Shadow DOM and Virtual DOM In React?

    The Shadow DOM is designed to scoping variables and CSS in web components and its a browser technology, while Virtual DOM is the concept is implemented by the browser libraries in javascript on the top of the browser APIs.

    What is React Fiber?

    In React v16 the react fiber the new reconciliation engine or reimplementation of core ago. mainly the use of React fiber is to increase its suitability for areas like animation layouts, gestures, ability to pause and assign the new work priority to different types of updates.

    What is The Main Goal of React Fiber?

    The Main Goal of the react fiber is to increase the suitability for areas like animation and gestures. The main feature of the React Fiber is to split the rendering work into different parts and spread it over multiple frames and it is called Incremental Rendering.

    What Are Controlled Components In React?

    When a component that can control the input elements within the form on the subsequent user inputs is called controlled inputs. E.g. I each state mutation will have an associated handler function.
    For example, to write all the names in uppercase letters, we use handleChange as below,
    handleChange(event) {

    What Is The Difference Between Create Element and Clone Element In React?

    React.createElement() function will transpile the JSX elements to createReact React elements which are going to be used for object representation of UI, while cloneElement cone an element and pass it to new props.

    What is Lifting State Up in React?

    When the data is changed and it is needed that the changed data is to be transferred then it lifts up the changed state up to the closest ancestor.e.g if two children wants to share same parents data then the state is moved to the parent rather than local elements.

    Latest News

    Add to your IT skills with short term and Professional courses from TOPS with Live Projects in Basic and Advance technologies.

    Who Should Do a Digital Marketing Course

    February 17, 2021

    The digital space is growing in the number of users, which has led to a growing demand for digital marketing. From marketing to the IT industry, digital marketing is a must for any business to thrive. So, practically, people across industries must take up a digital marketing course and add relevant skills to their resume. […]

    Which Country is Better for Indian Students for Study Abroad?

    April 18, 2019

    Canada is one amongst the most effective places to pursue your higher studies

    Study Abroad with Minimum finance

    March 31, 2019

    Canada is one amongst the most effective places to pursue your higher studies