React Flashcards

1
Q

What is the difference between the DOM and the virtual DOM? Why would we use a virtual DOM?

A

The virtual DOM is maintained in the runtime environment.
The DOM is maintained in the browser.

The virtual DOM is basically a copy of the DOM. We used this copy to make updates and changes and then when we need to we can update the DOM to reflect these changes. This reduces the amount of computational power needed to run a responsive web app because we don’t need to continuously render everything.

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

React is a library and AngularJS is a framework. What are the differences between a library and a framework?

A

Libraries allow you to access a number of useful functionalities however you need to manage their interaction with your code and the management of data flow yourself.

Frameworks are for the most part in charge of the data flow. There are specific places you must ‘plug in’ your code for it to work correctly.

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

What is one way data binding?

A

One way data binding is when changes to the model are reflected in the view but changes to the view are not reflected in the model. React uses one way data binding.

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

What is two way data binding?

A

Two way data binding is when changes to the model are reflected in the view and changes to the view makes changes to the model.

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

How does React make webpages more responsive?

A

React creates a virtual DOM so we don’t have to directly manipulate the DOM which is slower. It uses algorithms to only make the most efficient changes to the DOM.

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

What element do you usually attach a React hook to?

A

You usually attach a React Hook to the ‘root’ element of a HTML file.

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

What is the naming convention of a React component?

A

Components must be named with a capital letter.

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

How do we add a state to a component that is saved between renders?

A

We can use the ‘usestate’ keyword to add a local state to a component that is preserved between renders.
e.g useState();

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

What is good practice to check in a promise?

A

It is good practice to check if a promise has fulfilled and then add a catch if it has not.

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

Why do we want to use hooks in react?

A

React hooks allow us to use state and lifecycle features.

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

Write an example React function that initialises a count value to 0 and updates it by 1.

A
function Example() {
 const [count, setCount] = useState(0);
 setCount(count + 1)
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 3 stages of a react component lifecycle?

A
  1. Mounting - creating a component and inserting it into the DOM.
  2. Update - changes to props or state cause a render/
  3. Unmount - A clean up process that is called to remove a component from the DOM.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the benefits of single page applications?

A
  • They load much faster.
  • They only render as needed.
  • Caching allows for storage of local data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why is React routing useful?

A

React routing is used to make navigational components for single page applications without having to refresh the page every time a user navigates.

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