React Flashcards

1
Q

What is a webpack?

A

webpack, at its core, is a code bundler. It takes your code, transforms and bundles it, then returns a brand new version of your code.

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

What are the three main steps a webpack needs to do?

A

1) webpack needs to know the starting point of your application, or your root JavaScript file.
2) webpack needs to know which transformations to make on your code.
3) webpack needs to know to which location it should save the new transformed code.

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

What are the three different parts of a Component?

A
  1. states (data, arrays, etc.)
  2. lifecycle methods (life cycle events: allows you to hook into different lifecycle events)
  3. UI
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you specify what the UI of a component will look like?

A

Use the render() method

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

How do you call the react render?

A

ReactDOM.render()

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

What are the two arguments that ReactDOM.render() take?

A

The first is a react element, the second is where we want to render the react element in the DOM.

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

What is the syntax for using a component?

A

, where App is the name of the component.

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

What does webpack do?

A

Webpack bundles all of our modules together.

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

What does babel do?

A

Babel compiles JSX code into normal JavaScript so that the browser can understand it.

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

What does –save-dev do?

A

Saves the packages required to build your app to the json.package devdependicies object. DevDevependencies are all the packages your app needs to build. While DevDependencies are all the packages your app needs to run.

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

What does webpack-dev-server –open do?

A

Webpack-dev-server bundles your code into a local cache so it loads faster, and opens it on whichever localhost it is hosted on. This is faster than without because you would have to compile it to a dist folder. This is great for development because it is faster.

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

What is a react element?

A

React element describes what you want to see on the screen. Not so simply put, a React element is an object representation of a DOM node

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

What is the render component syntax?

A

ReactDOM.render(< Hello />, document.getElementById(‘app’))

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

What are props?

A

for passing data from one component to another child component and that system is through props. props are to components what arguments are to functions.

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

When making a list what do you need to include so React can efficiently know which items are removed or added?

A

A key. The syntax is:

arr.map(function(name) {
return <li> {name.name} </li>;
})}

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

What are PropTypes?

A

PropTypes allow you to declare the “type” (string, number, function, etc) of each prop being passed to a component. Then, if a prop passed in isn’t of the declared type, you’ll get a warning in the console.

17
Q

How can you tell what ‘this.’ is referencing?

A

Look at where the function is invoked, and what is the function being called on. What the function being called on (aka “to the left of the dot”, e.g: steve.sayName()) is what this is referencing.

18
Q

What does call do?

A

Every function has a call property which can be used to invoke the function on the argument. Any “this” used in the function will refer to the argument in the function call.

E.g. sayName.call(stacey); this invokes the sayName function on the stacey object.

You can supply additional arguments for parameters as the function after stacey

19
Q

what does apply do?

A

Apply is the same as call. It invokes a function on an object, and also parses out the additional arguments for parameters for the function from the data structure you give it.

E.g.

sayName.apply(stacey, languages);

where stacey is the object sayName is being invoked on, and languages is an array data structure which will be parsed out for the parameters on sayName

20
Q

what does bind do?

A

It returns a function based on the arguments that you provide. This explicitly defines this

21
Q

What is the benefit of an arrow function over a function declaration?

A

In an arrow function “this” refers to the context being invoked on. Whereas, function “this” refer to its internal context, unless you pass a ‘this’ as a second argument when mapping