3) React Basics Flashcards

1
Q

command for creating a react app?

A

npx create-react-app app-name

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

command script translation: react-scripts build

A

converts code from the src folder and fitting a lighter version of that code into the public folder.

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

command script translation: react-scripts build

A

creates a react app

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

command script translation: react-scripts test

A

runs the test code

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

command script translation: react-scripts eject

A

reveals the configuration code for Babel and webpack so that we can manage it ourselves

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

What project folder actually contains the files that we wll deplooy to a server?

A

public

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

What does the React library allow us to do?

A

We can write html like syntax in javascript files

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

You should never use the eject script until …

A

you have to

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

biggest advantage class components have over function components

A

state and lifecycle methods

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

JSX syntax for a button that changes a string state property onClick

A

this.setState({ string: “Abeche” })}>

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

What counts as a javascript expression inside of JSX?

A

Anything between curly braces

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

what property name does JSX use for html classes? why?

A

className

because class already means something in javascript

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

What method must you use to modify state in react? why?

A

this.setState()

it alertts the reactDOM that a change has been made

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

what does the map() method do?

A

returns the return of whatever function passed into it, iterated over each element in the array.

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

Why does react need each element in a state property array to have a unique ID

A

react needs to know which element to change if one of them changes so that it does not have to re-render everything.

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

what is the purpose of this line:

class App extends Component {

A

component is an object that we get from react that comes with useful functionality.

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

what is this called? (component):

import React, { Component } from “react”;

A

destructuring

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

Single page applications request ___ instead of ___

A

data instead of entire pages

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

What makes SPA so fast?

A

re-rendering the page is handled by javascript more so than server requests.

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

where do lifecycle methods come from?

A

the Component object from React.

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

What are lifecycle methods?

A

methods that get called at different stages of when the component gets rendered.

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

what does the componentDidMount() method do?

A

calls whatever code is inside of it when the component is rendered onto the DOM for the first time.

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

What is the significance of the bold code?

componentDidMount() {

fetch(“https://jsonplaceholder.typicode.com/users”)

.then((response) => response.json())

.then((users) => console.log(users));

}

A

presents the fetched data as a .json object (new promise) which allows us access to the information that we want.

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

steps for assigning API data to a state attribute? (3)

A
  1. fetch the data
  2. convert data to json
  3. save that json data to the state using setState()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
What kind of parameter does the setState method take?
an JS object
27
When a component relies on API data, the state attribute for that data should be initialized as ...
an empty array
28
What are the two ways of building components in React?
classes functions
29
Where do the props that the components receive come from?
properties passed into the component tags: ex.
30
what is the .children attribute of the props object?
anything in between the component tags: ex. **# Che**
31
Where should css styling be imported?
into the component that it styles
32
Why do we break our JSX code into so many components?
for reusability
33
state turns into ___ when it gets passed down.
props
34
the react developer tool is great for seeing how ...
information gets passed down.
35
What html tag do we use for search input
36
tag attribute that triggers an event everytime something changes in an element?
onChange
37
how do you reference the value of an input field in a callback function?
e.target.value
38
.setState is an ___ function call.
asynchronous
39
asynchronous vs synchronous
wait (runs other code while waiting) vs immediate
40
what is the second argument that you can put into this.setState()?
a callback function that allows us to do something with our state after we set it. (because asynchronous)
41
What is a synthetic event?
an event that the react robot reports
42
Why should you never use this.setState() in the render method of a component class?
rendering calls this.setState() and this.setState() triggers rendering; a never ending loop is created.
43
const { monsters, searchField } = this.state; what is the above technique called and what is it equivalent to?
destructuring ## Footnote const monsters = this.state.monsters; const searchField = this.state.searchField;
44
what does the filter method do?
acts on an array and returns all iterations of that array that meet the crtieria of the callback function.
45
how does .includes() method work?
returns a boolean based on if the value that it is acting on includes the argument passed into it.
46
When should you use a functional component over a class component?
when you don't think you will need state or lifecycle methods
47
Where should the state be placed?
in a trickle-down only position to whatever components need it.
48
When you write your own class methods the this. keyword gets bound ...
different depending on how you write that method.
49
How do you make sure that the context of "this" is correct in all of the methods before any code gets written.
put this code in the constructor method of the component class: this.handleChange = this.handleChange.bind(this);
50
what is .bind()?
a method on any function that returns a new function where the concept of this is set to whatever we passed to it.
51
How do you avoid using the .bind() method to define the "this"
use an arrow function when creating the method.
52
why do you not need .bind() when creating a arrow function method in a component class?
They automatically get lexical scoping meaning that they bind the this context to the place where they were defined in the first place (component class).
53
what is the advantage of using arrow functions instead of regular functions to define custom methods in a component class?
dont have to use the .bind() for each method.
54
Why don't we call a function "()" when it is an event handler?
because that envokes the function immediately, instead of only when the event occurs.
55
When defining custom class methods, what type of functions should be used?
arrow functions.
56
list the steps taken to add monsters-rolodex to github
1. Create a new repository 2. in the project folder enter: git remote add origin 3. add gh-pages: npm add gh-[ages 4. add a "homepage" key with a value of "homepage": "https://Che1195.github.io/monsters-rolodex", right under "private": true, 5. add two scripts: "predeploy": "npm run build", "deploy": "gh-pages -d build" 6. run "npm run deploy" in the terminal 7. run git add -A 8. git commit -m "adding files for github pages" 9. git push origin master
57
What can you use to build and serve a static webpage for free? (2)
create react app github pages
58
command line statement for creating a new file?
touch index.html
59
The virtual DOM is a complete copy of ... but in ...
actual dom javascript
60
What is the order that data flows between the state, actions, and views?
STATE updates the VIEWS which get ACTIONS that change the STATE
61
When you want to use this.setState() and it involves this.state, what does the syntax look like?
prevProps refers to the attributes that get passed into the class component prevState refers to the previous state before anychanges were made
62
When creating the constructor method and calling the props method what should be added as parameters in both?
props
63
When should you include the second argument callback function in a custom class method that uses .setState()?
Do you want to manipulate or use the state somehow after the update?
64
What is the mounting phase lifecycle method?
the phase in which the component is put on the DOM for the first time.
65
what is super() essentially saying? Why is this significant to react class components?
Give me the functionality of all the methods in my super class. gives us access to the lifecycle methods
66
What does the render() method do?
tells javascript that this is what the controller looks like and what it will display in terms of HTML.
67
API calls are made on the ____ lifecycle method.
componentDidMount()
68
What triggers the updating phase on our components?
1. New props 2. setState() 3. forceUpdate()
69
Does updating a component involve remounting it?
no, you just update what has been changed
70
What does the lifecycle method shouldComponentUpdate sit in between?
things the trigger rerendering, and the methods that follow.
71
How do you deny a component from updating using shouldComponentUpdate?
have it return false
72
How do you use prop/state changes to determine whether a component updates?
shouldComponentUpdate() { return nextProps.whatever !== this.props.whatever }
73
What is the phase that makes react so special?
Update Phase
74
what is componentWillUnmount used for?
code to be executed before the component is unmounted. usually for tidying up, and making the code more effecient.
75
list the 5 lifecycle components covered in this section.
1. componentDidMount() 2. componentDidUpdate() 3. componentWillUnmount() 4. shouldComponentUpdate() 5. render()