W6D5 Flashcards

1
Q

What is React?

A

React is a JS library for creating User Interface components.

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

What does React do?

A

When data in the User Interface changes, React updates the User Interface to match that data.

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

How does React work?

A

On the initial request, the component is rendered and the HTML markup is generated and added to the document. When the data is changed, Reacts will only re-render the bit of data that has been changed in the component. It does so by using a diff on what has been changed on the component and what was originally there. That minimum change can be applied to the DOM.

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

What is reconciliation?

A

The process of using a diff algorithm to check the difference between the DOM trees of the initial state and the changed state so that React can render a portion of a component in the most efficient way possible.

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

Where does React come from?

A

Facebook and Instagram

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

What is JSX?

A

JSX is a JS syntax extension that resembles HTML and XML.

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

What is XML?

A

XML stands for Extensible Markup Language. It is a markup language that defines a set of rules for encoding documents in a format that is both human and machine readable.

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

How can you use JS inside of JSX syntax?

A

Insert JS inside of {curly brackets} and insert this in between element tags or for markup attribute values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
Why would the below code cause an error? What kind of error does it give?
const myElement = (
	<h1>
	{
		1 + 2 + 3;
		4 + 5 + 6;
	}
	</h1>
);
A

It will give a syntax error, because the JSX expects JS expressions to be a single line expression.

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

Why do we use Babel?

A

JSX cannot be interpreted by browsers, so JSX code must be passed through a preprocess that transpiles it into vanillas JS.

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

What are components?

A

Components are the building blocks of a React view layer. They are JS functions that return HTML to be rendered onto a document.

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

What is root and why does it matter to React?

<div>I'm getting replaced :(</div>

A

“root” is the element which will serve as the hook into which we insert our React component.

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

What are the two ways to declare components?

A

Functional Component and Class Component

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

How is a class component written? Write a class component for ‘TodoList’.

A

class TodoList extends React.Component {

}

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

When do you write a functional component as opposed to a class component?

A

When a component does not have a lot of things it needs to do?

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

What is the equivalent way to write the below component? What kind of component is below?

class Message extends React.Component {
  render() {
    return (
      <div>{this.props.text}</div>
    );
  }
};
A
const Message = (props) => { 
return <div> {props.text} </div> 
};

The above is a functional component.

17
Q

What is a pure function?

A

A pure function is a function whose output is solely determined by its input and that has no side effects.

18
Q

What are two ways React components keep track of data?

A

Using two instance variables: this.props and this.state.

19
Q

What is the component and their props?

// app.jsx
import Dog from './dog';

const App = () => (

);

// dog.jsx
class Dog extends React.Component {
  constructor(props) {
     super(props);
  }
  render() {
    return (
      <div>Name: {this.props.name}, Breed: {this.props.breed}</div>
    );
  }
};

export default Dog;

A

The component is the Dog and the props are the properties of the dog, which is name and breed.

20
Q

What are the similarities between state and props?

A

They are both plain JS objects and trigger a render update.

21
Q

What are the differences between state and props?

A

To a component, props are initial values given to the component and are read only. Props are meant to be used when they aren’t going to be changed. State is used when incoming input needs to be maintained or updated.

22
Q

During initialization, what is state?

A

State is undefined.

23
Q

How do you change state at certain points of a lifecyle? What happens after changing state?

A

Using this.setState( ); Any time the state is changed, the component will call render().

24
Q

What are synthetic events?

A

They are ways to pass event listeners directly to your components via props.

25
Q

What is a transpiler?

A

source to source compiler; They are tools that read source code written in one programming language and produces the equivalent code in another language.

26
Q

What is Babel?

A

It is a transpiler that converts code into ES5.

27
Q

What is babel-core?

A

It is the transpiling engine itself

28
Q

babel-preset-es2015 and babel-preset-react?

A

are configurations that tell the core transpiler how to interpret Es6 and JSX respectively.

29
Q

What is object destructuring?

A

To extract parts of an object and assign those parts to different variables

30
Q

Why is it important to write super inside the constructor of a class component?

A

By creating a constructor method in the component declaration, it will overwrite the React class that is inheriting from. super(props) helps in preventing that.

31
Q

Why do we use React?

A

It simplifies and speeds up DOM manipulation. Components offer usability. Provides a reactive interface that updates when the data represents changes.

32
Q

What is the difference between jQuery and React?

A

jQuery manually goes into the DOM and replaces the old DOM. React has a virtual DOM, which it will use to change a small portion of data and never replace the entire DOM.