React Flashcards

1
Q

What is React?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

React features

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the advantages of using React?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the limitations of React?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is useState() in React?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are keys in React?

A

A key is a special string attribute that needs to be included when using lists of elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Importance of keys

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is JSX?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the differences between functional and class components?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the virtual DOM? How does react use the virtual DOM to render the UI?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why was virtual DOM introduced?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why can’t Browsers Read JSX?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Components?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Class Component?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a Functional Component?

A

A JavaScript/ES6 function that returns a React element is referred to as a functional component (JSX).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

There are 3 ways to style a react application with CSS:

A

Inline Styles
External Styling
CSS in JS

17
Q

What is the Use of render() in React?

A

Render() is used in the class component to return the HTML that will be displayed in the component. It is used to read props and state and return our JSX code to our app’s root component.

18
Q

What are Props?

A

Props transfer data from one component to the next (parent component to child component). They are typically used to render dynamically generated data.

19
Q

What is State in React?

A

State is a built-in React Object that is used to create and manage data within our components. It differs from props in that it is used to store data rather than pass data.

State is mutable (data can change) and accessible through this.state().

20
Q

How to Update the State of a Component in React

A

Have to use the setState() method which updates the component’s state object and re-renders the component.

21
Q

How to Differentiate Between State and Props

A

State and props are JavaScript objects with distinct functions.

Props are used to transfer data from the parent component to the child component, whereas state is a local data storage that is only available to the component and cannot be shared with other components.

22
Q

What is an Event in React?

A

In React, an event is an action that can be triggered by a user action or a system generated event. Mouse clicks, web page loading, key press, window resizes, scrolls, and other interactions are examples of events.

23
Q

What is Redux?

A

Redux is a popular open-source JavaScript library for managing and centralizing application state

24
Q

What are React Hooks?

A

React hooks allow us to use state and other React features without having to write a class.

They do not operate within classes, but rather assist us in HOOKing into React state and lifecycle features from function components.
React hooks were added in v16.8.

25
Q

Explain the useState() Hook

A

The useState Hook enables the use of state variables in functional components. You can pass the initial state to this function, and it will return a variable containing the current state value (not necessarily the initial state) and another function to update this value.

26
Q

Explain the useEffect() Hook

A

The useEffect Hook allows you to perform side effects in your components like data fetching, direct DOM updates, timers like setTimeout(), and much more.

This hook accepts two arguments: the callback and the dependencies, which allow you to control when the side effect is executed.

27
Q

What’s the Use of the useMemo() Hook?

A

The useMemo() hook is used in functional components to memoize expensive functions so that they are only called when a set input changes rather than every render.

28
Q

What Is the useRefs Hook?

A

The useRefs() hook, also known as the References hook, is used to store mutable values that do not require re-rendering when they are updated. It is also used to store a reference to a specific React element or component, which is useful when we need DOM measurements or to directly add methods to the components.

29
Q

What are Custom Hooks?

A

Custom Hooks are a JavaScript function that you write to allow you to share logic across multiple components, which was previously impossible with React components.

30
Q

What is Context in React?

A

Context is intended to share “global” data for a tree of React components by allowing data to be passed down and used (consumed) in whatever component we require in our React app without the use of props. It allows us to share data (state) more easily across our components.

31
Q

What is React Router?

A

React router is a standard library used in React applications to handle routing and allow navigation between views of various components.

npm install – -save react-router-dom