React Flashcards
What is React?
React is a declarative, efficient, flexible open source front-end JavaScript library developed by Facebook in 2011. It follows the component-based approach for building reusable UI components, especially for single page application. It is used for developing interactive view layer of web and mobile apps. It was created by Jordan Walke, a software engineer at Facebook. It was initially deployed on Facebook’s News Feed section in 2011 and later used in its products like WhatsApp & Instagram.
What are the features of React?
React framework gaining quick popularity as the best framework among web developers. The main features of React are:
JSX Components One-way Data Binding Virtual DOM Simplicity Performance
What are the most crucial advantages of using React?
React is easy to learn and use
React comes with good availability of documentation, tutorials, and training resources. It is easy for any developer to switch from JavaScript background to React and easily understand and start creating web apps using React. Anyone with little knowledge of JavaScript can start building web applications using React.
React follows the MVC architecture.
React is the V (view part) in the MVC (Model-View-Controller) architecture model and is referred to as “one of the JavaScript frameworks.” It is not fully featured but has many advantages of the open-source JavaScript User Interface (UI) library, which helps execute the task in a better manner.
React uses Virtual DOM to improve efficiency.
React uses virtual DOM to render the view. The virtual DOM is a virtual representation of the real DOM. Each time the data changes in a react app, a new virtual DOM gets created. Creating a virtual DOM is much faster than rendering the UI inside the browser. Therefore, with the use of virtual DOM, the efficiency of the app improves. That’s why React provides great efficiency.
Creating dynamic web applications is easy.
In React, creating a dynamic web application is much easier. It requires less coding and gives more functionality. It uses JSX (JavaScript Extension), which is a particular syntax letting HTML quotes and HTML tag syntax to render particular subcomponents.
React is SEO-friendly.
React facilitates a developer to develop an engaging user interface that can be easily navigated in various search engines. It also allows server-side rendering, which is also helpful to boost the SEO of your app.
React allows reusable components.
React web applications are made up of multiple components where each component has its logic and controls. These components provide a small, reusable piece of HTML code as an output that can be reused wherever you need them. The code reusability helps developers to make their apps easier to develop and maintain. It also makes the nesting of the components easy and allows developers to build complex applications of simple building blocks. The reuse of components also increases the pace of development.
Support of handy tools
React provides a lot of handy tools that can make the task of the developers understandable and easier. Use these tools in Chrome and Firefox dev extension, allowing us to inspect the React component hierarchies in the virtual DOM. It also allows us to select the particular components and examine and edit their current props and state.
React has a rich set of libraries.
React has a huge ecosystem of libraries and provides you the freedom to choose the tools, libraries, and architecture for developing the best application based on your requirement.
Scope for testing the codes
React web applications are easy to
What are the biggest limitations of React?
React is just a library. It is not a complete framework.
It has a huge library which takes time to understand.
It may be difficult for the new programmers to understand and code.
React uses inline templating and JSX, which may be difficult and act as a barrier. It also makes the coding complex.
What is JSX?
JSX stands for JavaScript XML. It is a React extension which allows writing JavaScript code that looks similar to HTML. It makes HTML file easy to understand. The JSX file makes the React application robust and boosts its performance. JSX provides you to write XML-like syntax in the same file where you write JavaScript code, and then preprocessor (i.e., transpilers like Babel) transform these expressions into actual JavaScript code. Just like XML/HTML, JSX tags have a tag name, attributes, and children.
Why can’t browsers read JSX?
Browsers cannot read JSX directly because they can only understand JavaScript objects, and JSX is not a regular JavaScript object. Thus, we need to transform the JSX file into a JavaScript object using transpilers like Babel and then pass it to the browser.
Why we use JSX?
It is faster than regular JavaScript because it performs optimization while translating the code to JavaScript.
Instead of separating technologies by putting markup and logic in separate files, React uses components that contain both.
t is type-safe, and most of the errors can be found at compilation time.
It makes easier to create templates.
What do you understand by Virtual DOM?
A Virtual DOM is a lightweight JavaScript object which is an in-memory representation of real DOM. It is an intermediary step between the render function being called and the displaying of elements on the screen. It is similar to a node tree which lists the elements, their attributes, and content as objects and their properties. The render function creates a node tree of the React components and then updates this node tree in response to the mutations in the data model caused by various actions done by the user or by the system.
Explain the working of Virtual DOM.
Virtual DOM works in three steps:
- Whenever any data changes in the React App, the entire UI is re-rendered in Virtual DOM representation.
React Interview Questions1
2. Now, the difference between the previous DOM representation and the new DOM is calculated.
React Interview Questions2
3. Once the calculations are completed, the real DOM updated with only those things which are changed.
How is React different from Angular?
Angular Release: 2010 Language: JavaScript, HTML Type: Open Source MVC Framework Rendering: Client-Side Data-Binding: Bi-directional DOM: Regular DOM Testing: Unit and Integration Testing App Architecture: MVC Performance: Slow
React Release: 2013 Language: JSX Type: Open Source JS Framework Rendering: Server-Side Data-Binding: Uni-Directional DOM: Virtual DOM Testing: Unit Testing App Architecture: Flux Performance: Fast due to virtual DOM
How React’s ES6 syntax is different from ES5 syntax?
The React’s ES6 syntax has changed from ES5 syntax in the following aspects.
require vs. Import exports vs. export component and function props state
What is React Native?
Initial release in 2015.
It is used for developing mobile applications.
It is not platform independent. It takes more effort to be executed on all platforms.
It comes with built-in animation libraries.
It has built-in Navigator library for navigating mobile applications.
It does not use HTML tags.
In this, Native uses its API to render code for mobile applications.
What is the difference between Real DOM and Virtual DOM?
Real DOM
Updates slower, can directly update HTML.
The virtual DOM updates the JSX if the element updates.
Real DOM manipulation is very expensive.
A lot of memory wastage in the real DOM.
Virtual DOM
Update faster, cannot directly update HTML.
Virtual DOM is manipulated easily.
No memory wastage in the virtual DOM.
What do you understand from “In React, everything is a component.”
In React, components are the building blocks of React applications. These components divide the entire React application’s UI into small, independent, and reusable pieces of code. React renders each of these components independently without affecting the rest of the application UI. Hence, we can say that, in React, everything is a component.
Explain the purpose of render() in React.
It is mandatory for each React component to have a render() function. Render function is used to return the HTML which you want to display in a component. If you need to rendered more than one HTML element, you need to grouped together inside single enclosing tag (parent tag) such as <div>, , etc. This function returns the same result each time it is invoked.
</div>
What is Props?
Props stand for “Properties” in React. They are read-only inputs to components. Props are an object which stores the value of attributes of a tag and work similar to the HTML attributes. It gives a way to pass data from the parent to the child components throughout the application.
It is similar to function arguments and passed to the component in the same way as arguments passed in a function.
Props are immutable so we cannot modify the props from inside the component. Inside the components, we can add attributes called props. These attributes are available in the component as this.props and can be used to render dynamic data in our render method.
What is a State in React?
The State is an updatable structure which holds the data and information about the component. It may be changed over the lifetime of the component in response to user action or system event. It is the heart of the react component which determines the behavior of the component and how it will render. It must be kept as simple as possible.
Differentiate between States and Props.
Props
Are read-only.
Are immutable.
Props allow you to pass data from one component to other components as an argument.
Props can be accessed by the child component, and are used to communicate between components.
Stateless components can have props.
Props make components reusable.
Props are external and controlled by whatever renders the components.
State
State changes can be asynchronous.
State is mutable.
State holds information about the components.
State cannot be accessed by child components.
States can be used for rendering dynamic changes with the component.
Stateless components cannot have state.
The State cannot make components reusable.
State is internal and controlled by the component itself.
How can you update the State of a component?
We can update the State of a component using this.setState() method. This method does not always replace the State immediately. Instead, it only adds changes to the original State. It is a primary method which is used to update the user interface(UI) in response to event handlers and server responses.
Differentiate between stateless and stateful components.
Stateless Component
The stateless components do not hold or manage state.
It does not contain the knowledge of past, current, and possible future state changes.
It is also known as a functional component.
It is simple and easy to understand.
It does not work with any lifecycle method of React.
The stateless components cannot be reused.
Stateful Component
It can contain the knowledge of past, current, and possible future changes in state.
It is also known as a class component.
It is complex as compared to the stateless component.
It can work with all lifecycle method of React.
The stateful components can be reused.
What is arrow function in React? How is it used?
The Arrow function is the new feature of the ES6 standard. If you need to use arrow functions, it is not necessary to bind any event to ‘this.’ Here, the scope of ‘this’ is global and not limited to any calling function. So If you are using Arrow Function, there is no need to bind ‘this’ inside the constructor. It is also called ‘fat arrow ‘(=>) functions.
What is an event in React?
An event is an action which triggers as a result of the user action or system generated event like a mouse click, loading of a web page, pressing a key, window resizes, etc. In React, the event handling system is very similar to handling events in DOM elements. The React event handling system is known as Synthetic Event, which is a cross-browser wrapper of the browser’s native event.
Handling events with React have some syntactical differences, which are:
React events are named as camelCase instead of lowercase.
With JSX, a function is passed as the event handler instead of a string.
How do you create an event in React?
<div>Click Me</div>
What are synthetic events in React?
A synthetic event is an object which acts as a cross-browser wrapper around the browser’s native event. It combines the behavior of different browser’s native event into one API, including stopPropagation() and preventDefault().