General React Questions Flashcards
Differentiate between Real DOM and Virtual DOM.
Real Dom
- It updates slow.
- Can directly update HTML.
- Creates a new DOM if element updates.
- DOM manipulation is very expensive.
- Too much of memory wastage.
Virtual Dom
- It updates faster.
- Can’t directly update HTML.
- Updates the JSX if element updates.
- DOM manipulation is very easy.
- No memory wastage.
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?
- It uses the virtual DOM instead of the real DOM.
- It uses server-side rendering.
- It follows uni-directional data flow or data binding.
List some of the major advantages of React.
- It increases the application’s performance
- It can be conveniently used on the client as well as server side
- Because of JSX, code’s readability increases
- React is easy to integrate with other frameworks like Meteor, Angular, etc
- Using React, writing UI test cases become extremely easy
What are the limitations of React?
- React is just a library, not a full-blown framework
- Its library is very large and takes time to understand
- It can be little difficult for the novice programmers to understand
- Coding gets complex as it uses inline templating and JSX
What is JSX?
- shorthand for JavaScript XML
- type of file used by React which utilizes the expressiveness of JavaScript along with HTML like template syntax
- makes applications robust and boosts its performance
What do you understand by Virtual DOM? Explain its working.
- Virtual DOM is a lightweight JavaScript object which originally is just the copy of the real DOM
- It is a node tree that lists the elements, their attributes and content as Objects and their properties
- React’s render function creates a node tree out of the React components
- React updates this tree in response to the mutations in the data model which is caused by various actions done by the user or by the system.
- Whenever any underlying data changes, the entire UI is re-rendered in Virtual DOM representation.
- Then the difference between the previous DOM representation and the new one is calculated.
- Once the calculations are done, the real DOM will be updated with only the things that have actually changed.
Why can’t browsers read JSX?
- Browsers can only read JavaScript objects but JSX in not a regular JavaScript object.
- Thus to enable a browser to read JSX, first, we need to transform JSX file into a JavaScript object using JSX transformers like Babel and then pass it to the browser.
Components
Reusable pieces of the application UI that has inner dynamic functionality and state.
Classes
Interfaces of properties and methods that will be assigned to object instances.
Inheritance
The extension of existing properties and methods from a parent class to a subclass. The subclass extends the parent class to inherit the base parent class’s methods and properties.
State
The internal data of a React component. The state can be updated through interactions with the component during the application.
SetState
The official way to update state in a React component. It is a react rule to not modify the state directly. Instead, provide new values for keys in the state, using the setState() method. The setState() method recalls the render method when complete, giving the component the chance to reflect changes in the UI.
.bind
A JavaScript method that passes the this object down from a component to a helper methods. Crucial for components to pass down the this.setState()
method to helper methods.
Class Properties and Initializers
An alternative syntax for declaring the state and within components that automatically binds the this
object.