ReactJS Flashcards

1
Q

What is the Virtual DOM?

A

The virtual DOM is a programming concept where a “virtual” representation of a UI is kept in memory and synced with the “real” DOM using a library such as ReactDOM. This process is called reconciliation.

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

What is ReactDOM?

A

ReactDOM is a package that provides DOM specific methods that can be used at the top level of a web app to enable an efficient way of managing DOM elements of the web page. The package provides developers with an API containing methods such as render() and findDOMNode() and is the glue between React and the DOM.

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

How do you convert a function to a React class is ES6?

A

Create a class by extending React.Component(), adding a single method to it called render, and return a React/HTML element.

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

How do you add a local state to a React class?

A

To add a local state to a class, add a class constructor that will assign the initial this.state(). Then you can access the state values by using this.state.

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

What are the three main lifecycle methods that are run when a component is initially mounted?

A

constructor(), render(), and componentDidMount().

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

What are the three main lifecycle methods that are run when a component is updated?

A

shouldComponentUpdate(), render() and componentDidUpdate().

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

What is the lifecycle method that is called when a component is being removed from the DOM?

A

componentWillUnmount().

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

What are hooks and what are the benefits of using them?

A

React hooks are an addition of React 16.8 and let you use a local state without creating a class.

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

What is the use of super(props) in react classes?

A

super(props) is called in the constructor of react classes and refers to the parent constructor, specifically the React.Component class. This allows the subclass to access methods of the parent class.

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

How does React work?

A

React creates a virtual DOM. When state changes in a component it firstly runs a “diffing” algorithm, which identifies what has changed in the virtual DOM. The second step is reconciliation, where it updates the real DOM using DOM manipulation with the results of diff.

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

What is JSX and what does it stand for?

A

JSX stands for JavaScript XML and is an extension that makes it easer to read and write HTML in react.

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

What are the benefits of using JSX?

A

Because after compilation, JSX become become regular javascript objects. This means you can use JSX inside if statements, in loops, assign it to variables, accept it as arguments and return it from functions.

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

What is the name of the transpiler that convert JSX to javascript objects.

A

Babel is the transpiler that convert JSX to javascript objects.

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

What are the two ways you can create classes in React?

A

By extending React.component and using Reacts createClass().

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

What is the difference between a class component and a functional component?

A

Class components allows us to use additional features such as local state and lifecycle hooks. In comparison, when our component just receives props and renders them to the page, this is a ‘stateless component’, for which a pure function can be used.

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

What is a redux?

A

The idea of redux is that the entire application state is kept in a single store, of which is simply a javascript object. The only what to change to state would be to to fire actions from the application and write reducers for these action that in turn modify the state.

17
Q

What is the difference between React.Component and React.PureComponent?

A

Although both Component and PureComponent allow you to create react classes, PureComponent handles the shouldComponentUpdate lifecycle method for us. When props or state changes, PureComponent will do a shallow comparison on both those variables and will re-render by default whenever shouldComponentUpdate() is called.

18
Q

What are controlled and uncontrolled components?

A

A controlled component is one that takes its current value through props and notifies changes through callbacks like onChange(). A parent component is essentially controlling the values of the components props. In comparison, an uncontrolled component is one that stores its own state internally.