React Flashcards

1
Q

What is composition?

A

Composition is the combining of smaller functions to make larger more complex functions.

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

What are the benefits of composition?

A
  1. Code Reuse

2. Utilize the “JOT” function rule

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

Describe the difference between Declarative Code and Imperative Code

A

Declarative code is where you instruct JavaScript on what you want to be done.

Imperative code is where you provide the steps to come up with a solution.

When you get in a car, you declare that the temperature should be 71 degrees.

However, some cars require you to turn nobs and fiddle with the state to achieve 71 degrees as you are driving, that is Imperative behavior.

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

Why is React so great?

A

Its compositional model
Its declarative nature
The way data flows from parent to child; unidirectional flow through the Virtual DOM tree.
Because React conceptually re-renders everything whenever anything changes, the code is safe by default and it also means less work has to be done by the programmer because they don’t have to deal with updating the state of the UI themselves.

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

What are two ways to render UI with React

A

You can render UI utilizing plain JSX like so:

let someData = 'Hello, World'
const element = <ol>
<li>{someData}</li>
</ol>
let element = React.createElement(
 return (
   <div>  
     <h1>Hello, World</h1>
  </div>
 );
);
function helloWorld(props) {
    return (
);

}

helloWorld.PropTypes {
// pass in some requirements and
// structure of component

}

ReactDOM.render(element, document.getElementById(‘root’))

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

What is a prop

A

A prop is what allows you to pass data into a component.

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

How is React Unidirectional?

A

React is unidirectional because data flows from parent to child.

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

At what layer would you change state?

A

State should be changed in the layer that is storing the data, which is the upper most layer; parent.

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

Before React there was a major source of bugs for front-end developers, what was it?

How did React solve this issue?

A

A major source of bugs for front-end developers was around synchronizing the data model with the DOM; it is very difficult to make sure that whenever data changes, that the UI is consistent with those changes.

React solves this through a pure JavaScript representation of the DOM, implementing diffing clientside and then using events that send simple commands: create, update, delete.

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

What are the benefits of re-rendering everything whenever anything changes in your data model?

A

A layer of safety is introduced and time is saved for the developer because they only need to write the creation path; updates are taken care of for them.

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

Describe how data flows with two-day data binding; the opposite of unidirectional data flow.

What is the flaw?

A

In two-way data binding, the data is kept in sync throughout the app no matter where it is updated.

Any part of an application that has that binding can change the state of the data, so you have to keep in mind where the data is being updated and how that change affects other areas.

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

What is the virtual DOM?

A

The virtual DOM is an internal representation of the DOM that contains elements returned from react components. The nice thing about the virtual DOM is that it avoids creating DOM nodes and accessing existing ones beyond necessity.

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

What is the diffing algorithm?

A

Diffing determines how to make efficient changes to the DOM.

With diffing, old DOM nodes are taken out and replaced only when necessary.

This way, our app doesn’t perform any unnecessary operations to figure out when to render content.

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

Why split JSX over multiple lines?

A

For readability and also to avoid automatic semicolon insertion.

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

How does React prevent injection attacks?

A

React escapes any values in JSX before rendering them; everything is converted to a string preventing XSS cross-site scripting attacks.

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

How is React following the separation of concerns approach versus the separation of technology one.

A

By adding loosely coupled units into components, instead of separating different types of technologies and logic into separate files.

This introduces a lot of power of course, which is why the single responsibility rule should be followed.

17
Q

What is a React Node?

A

The primary type or value that is created when using React.

It is a light, stateless, immutable, virtual representation of a DOM node.