Basics Flashcards

1
Q

What is “state”?

A

All internal data that defines an application at a given point in time

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

What is React’s approach to reactive UI rendering?

A

You declare how state is represented as visual elements of the DOM.

From then on, React automatically updates the DOM to reflect state changes.

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

What is React’s ‘raison d’etre’?

A

Reduce the complexity of creating/maintaining UIs

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

What are components?

A

Self-contained, concern-specific building blocks that are easy to reuse, extend and maintain.

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

Give 3 reasons why JSX is great for user interfaces?

A

1) it’s declarative
2) it’s easy to spot the relationship between elements
3) it’s easy to visualize the overall structure of your UI

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

What does SPA stand for?

A

Single Page Application

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

What are SPAs constantly doing?

A

1) Fetching new data

2) Transforming parts of the DOM as the user interacts through the UI

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

What does DOM stand for?

A

Document Object Model

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

What happens when interfaces grow more complex?

A

Becomes difficult to:

1) Examine the current state of the application
2) Make the necessary changes on the DOM to update it

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

What technique do other JS frameworks use to keep the interface in sync with state?

A

Data binding

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

For performance reasons, it’s not viable to trash and re-render the entire interface every time state changes.
What is React’s solution to this?

A

The ‘Virtual DOM’ :

An in-memory, lightweight representation of the DOM

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

When to use a Class Component over a Function Component?

A

Class components

  • the render() method will be called, whenever the state of the components changes.
  • should be preferred whenever we have the requirement with the state of the component.

Functional components

  • render the UI based on the props
  • no render() method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are props in React?

A
  • Inputs to components
  • They pass custom data to your component
  • They trigger state changes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why should we not update the state directly?

A
  • If you try to do it directly, it won’t re-render the component
  • use setState() method, it schedules an update to components state object which triggers the component to re-render
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to pass a parameter to an event handler or callback?

A

You can use an arrow function to wrap around an event handler and pass parameters:

this.handleClick(id)} />

This is an equivalent to calling .bind:

Apart from these two approaches, you can also pass arguments to a function which is defined as arrow function

handleClick = (id) => () => {
console.log(“Hello, your ticket number is”, id)
};

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

What are synthetic events in React?

A
  • a cross-browser wrapper around the browser’s native event.
  • It’s API is same as the browser’s native event, including stopPropagation() and preventDefault(), except the events work identically across all browsers.
17
Q

What is “key” prop and what is the benefit of using it in arrays of elements?

A

A key is a special string attribute you should include when creating arrays of elements. Key prop helps React identify which items have changed, are added, or are removed.

18
Q

How does the Virtual Dom work?

A

1) Whenever any underlying data changes, the entire UI is re-rendered in Virtual DOM representation.
2) Then the difference between the previous DOM representation and the new one is calculated.
3) Once the calculations are done, the real DOM will be updated with only the things that have actually changed.