React Flashcards
What is React?
React is a front-end and open-source JavaScript library which is useful in developing user interfaces specifically for applications with a single page. It is helpful in building complex and reusable user interface(UI) components of mobile and web applications as it follows the component-based approach.
React features
It will make use of the virtual DOM rather than real DOM (Document Object Model) as RealDOM manipulations are expensive.
It follows unidirectional data binding or data flow.
It uses reusable or composable UI components for developing the view.
What are the advantages of using React?
It has a shorter learning curve for JavaScript developers and a large number of manuals, tutorials, and training materials are available because of its active community.
React is search engine friendly
It makes it easier to create rich UI and custom components.
React has quick rendering
The use of JSX allows us to write code that is simpler, more appealing, and easier to understand.
What are the limitations of React?
React is not a full-blown framework as it is only a library.
It might be difficult for beginner programmers to understand React.
Coding might become complex as it will make use of inline templating and JSX.
What is useState() in React?
The useState() is a built-in React Hook that allows you to have state variables in functional components.
It should be used when the DOM has something that is dynamically manipulated/controlled.
What are keys in React?
A key is a special string attribute that needs to be included when using lists of elements.
Importance of keys
Keys help React to identify which elements were added, changed or removed.
Keys should be given to array elements for providing a unique identity for each element.
Without keys, React does not understand the order or uniqueness of each element.
With keys, React has an idea of which particular element was deleted, edited, and added.
What is JSX?
JSX stands for JavaScript XML. It allows us to write HTML inside JavaScript and place them in the DOM without using functions like appendChild( ) or createElement( ).
JSX provides syntactic sugar for React.createElement( ) function.
What are the differences between functional and class components?
Before the introduction of Hooks in React, functional components were called stateless components and were behind class components on a feature basis. After the introduction of Hooks, functional components are equivalent to class components.
What is the virtual DOM? How does react use the virtual DOM to render the UI?
Virtual DOM is a virtual representation of the real DOM. It is kept inside the memory and is synced with the real DOM by a library such as ReactDOM.
Why was virtual DOM introduced?
DOM manipulation is an integral part of any web application, but DOM manipulation is quite slow when compared to other operations in JavaScript. The efficiency of the application gets affected when several DOM manipulations are being done. Most JavaScript frameworks update the entire DOM even when a small part of the DOM changes.
For example, consider a list that is being rendered inside the DOM. If one of the items in the list changes, the entire list gets rendered again instead of just rendering the item that was changed/updated. This is called inefficient updating.
Why can’t Browsers Read JSX?
JSX is not a valid JavaScript code, and there is no built-in implementation that allows the browser to read and understand it.
We need to transpile the code from JSX into valid JavaScript code that the browser can understand, and we use Babel, a JavaScript compiler/transpiler.
What are Components?
A component is a self-contained, reusable code block that divides the user interface into smaller pieces rather than building the entire UI in a single file.
There are two kinds of components in React: functional and class components.
What is a Class Component?
Class components are ES6 classes that return JSX and necessitate the use of React extensions.
Because it was not possible to use state inside functional components in earlier versions of React (16.8), functional components were only used for rendering UI.
What is a Functional Component?
A JavaScript/ES6 function that returns a React element is referred to as a functional component (JSX).