3 Flashcards

1
Q

12.

A

S

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

What does nvm stand for?

A

Node version manager.

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

What is a nvm?

A

A simple way in the terminal for us to switch node versions.

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

What is npx?

A

A package runner tool that comes with npm 5.2.

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

What does npx do?

A

It runs a command of a package without installing it explicitly.

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

npx runs a command of a package without installing it explicitly. What does this mean?

A

Before we had npx we had to run

npm install -g create-react-app

Then we ran the create react app command to create our app.

create-react-app my-app

npx allows us to not install this global version of create-react-app and just simply run that one command to create our app.

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

How can you get older documentation of React?

A

By clicking on the version number in the Navbar of the site.

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

What can you do if you’re unable to get the create-react-app started?

A

You can use a code sandbox to use React in the browser.

https://codesandbox.io/s/new

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

13.

A

E

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

What is recommended after installing VSCode?

A

Add the code shell command to your terminal.

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

How do you add the code shell command to your terminal?

A

hold cmd shift P. Then type command. Here, you’ll see ‘Shell Command: Install ‘code’ command in PATH’. Click that and it will install the code command to your path.

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

What happens when you have your path setup?

A

You’re now able to use the code dot command to open up files and folders inside of your terminal.

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

What is the terminal?

A

The terminal is going to be the main way we navigate around our application as well as modify our files.

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

How can you install node?

A

The easiest way is to use nvm.

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

How do you install nvm?

A
Go to (link in resource folder). When you get to the link, scroll down to the the section called 'Installation and Update'. Copy the line of code and paste it into the terminal. This will clone down the nvm package and add it to your existing shell, which is the thing we're running inside of our terminal.
NOTE: When you have nvm we have to close the terminal and relaunch it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What should you do when you first install nvm?

A

Type in command -v nvm to check if it installed correctly.

NOTE: If you see nothing listed this means that nvm isn’t yet loaded to our shell.

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

Where can we find information that helps us when we install and check the version of nvm but nothing gets listed?

A

Scroll down on the webpage we used to find the line of code that we used to install nvm in the terminal and find the section on ‘nvm: command note found’.

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

What should you do if you don’t see anything listed after installing and checking the version of nvm?

A

First check to see if we have a bash profile.

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

How can we check to see if we have a bash profile?

A

By simply typing nano ~/.bash_profile. If after pressing enter nothing happens meaning there is no bash profile, instead of nano replace it with touch and then run nano ~/.bash_profile again.

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

What does touch do when entered in the terminal? (with ~/.bash_profile?)

A

It will open a new bash profile for you.

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

What do you do when you’re inside of the bash profile?

A

If at the bottom we see nothing that relates to nvm we need to run the line (from to website) of running

source ~/.bashrc

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

How would you save…….

A

Press cmd + x and then y and lastly enter.

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

What do you do after you’ve ……

A

type source ~/.bash_profile

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

What does typing source ~/.bash_profile in the …. do?

A

It uploads and reruns our bash profile that we just made made changes to.

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

What should all of this have done…….?

A

Now when we type nvm something will appear instead of nvm command not found.

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

If after typing nvm you get something other than nvm not found what does this mean?

A

We have nvm installed.

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

How can we install node using nvm?

A

First figure out what node version we want to run by going to the node website e.g. 10.16.0 LTS. Go to the terminal and type in nvm install 10.16.0 or any other version of node.
NOTE: Typing in nvm install node will give you the latest version of node.

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

How after installing node can we use it?

A

By typing in nvm use 10.16.0 in the terminal.

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

What is also installed when installing node?

A

npm.

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

What are we going to use npm for?

A

To manage the packages we use inside of our JavaScript applications.

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

What are packages?

A

Libraries.

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

How can you check if you have node installed?

A

By typing node -v in the terminal.

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

How could you check if you have npm installed?

A

By typing npm -v in the terminal.

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

What is yarn?

A

Another package manager.

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

Who made yarn?

A

Facebook.

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

When was yarn made?

A

During a time when npm had some issues.

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

How do you install yarn?

A

Go to the yarn resource and copy the yarn code and paste in into the terminal.

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

How can you clear the terminal?

A

By typing clear.

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

How can you check if yarn is installed?

A

By typing yarn -v

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

What is something to note when using yarn or npm?

A

You can switch between them freely, however, in one project you should ideally one use one or the other (they shouldn’t be used in the same folder).

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

14.

A

E

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

15.

A

N

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

How would you install dependencies from package.json in both npm and yarn?

A

npm install

yarn

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

How would you install a package and add to package.json in both npm and yarn?

A

npm install package –save

yarn add package

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

How would you install a devDependency to package.json in both npm and yarn?

A

npm install package –save-dev

yarn add package –dev

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

How would you remove a dependency from package.json in both npm and yarn?

A

npm uninstall package –save

yarn remove package

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

How would you upgrade a package to its latest version in both npm and yarn?

A

npm update –save

yarn upgrade

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

How would you install a package globally in both npm and yarn?

A

npm install package -g

yarn global add package

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

16.

A

Y

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

How can you get a new font on you computer?

A

Download it, unzip the file and install the font on your computer.

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

How would you switch your VSCode over to using a different font?

A

Navigate into your editor settings and change your font over to a new font; also make sure to enable font ligatures!

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

What do you also have to do add in order to enable the cursive?

A

The extension snazzy operator.

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

What should you do if you install extensions in VSCode and the changes don’t load?

A

Restart your editor.

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

17.

A

C

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

What is create-react-app?

A

A tool to help developers get started with building React projects quickly.

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

Who built create-react-app?

A

Facebook.

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

What is the reason for the create-react-app tool?

A

React is written in a version of JavaScript that is further along tan the version of JavaScript that our browsers understand.

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

What does Babel and WebPack do?

A

They take the React code that we write and convert them into that older version of JavaScript and HTML.

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

Why do we need Babel and WebPack?

A

Because our browser can’t understand the code we write.

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

What does create-react-app do?

A

It allows us to create a React app fast that already has all of the configuration you need to get started.

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

How can we use the create-react-app tools?

A

We call npx create-react-app my-app in the command line.

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

Before you use create-react-app what should you do?

A

Make sure you’re running the latest version of node.

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

How can you install nvm?

A

nvm install 10.15.3

NOTE: It’s recommended to install the latest LTS version of node.

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

How do you use nvm?

A

nvm use 10.15.3

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

What should you do after you use nvm?

A

Use the create-react-app tool.

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

How do you use the create-react-app tool?

A

We call npx create-react-app my-app in the command line.

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

What happens when you run this command?

npx create-react-app my-app

A

create-react-app is now building out our project and setting up the files, the WebPack, the Babel, all the things we need so we can start using React right away.

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

What should you do after running create-react-app?

A

cd into it.

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

18.

A

C

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

How can you see what create-react-app has made for us?

A

After cding into the correct directory, we use the ls command.

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

What has create-react-app made for us?

A

A README.md file, a node_modules folder, a package.json file, a public folder, a src folder and yarn.lock file.

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

Where are our dependencies?

A

In node_modules.

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

How can you open this up in VSCode?

A

By typing code .

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

What is in the package.json file?

A

It’s included for us react and react-dom as well as another library called react-scripts.

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

What does react-scripts do for us?

A

It’s what allows us to not have to worry about WebPack and Babel.

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

What scripts does react-scripts include for us?

A

start, build, test and eject.

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

What do the react-scripts scripts do?

A

They call react-scripts to do there respective things.

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

What does the start react-scripts script do?

A

It starts the project.

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

How would you use the start script?

A

In the terminal, in the correct folder type yarn start.

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

What happens when you use the start script?

A

It serves up a sample application of React inside of localhost:3000.

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

Where does our application live?

A

In the src folder.

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

Where does all the React code we write live?

A

In the src folder.

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

What is the public folder?

A

Where all the older versions of JavaScript and HTML files that the browser can understand live.

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

What does the build react-scripts script do?

A

It turns all the React code in the src folder into the version that the browser can understand and puts it inside of the public folder.

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

What does the test react-scripts script do?

A

Runs the test code that we write.

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

What does the eject react-scripts script do?

A

It takes out all of the configuration files that’s hidden from us for Babel and WebPack in case we wanted to manage it ourselves.

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

How do we import React into our project?

A

import React from ‘react’;

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

What does this line of code do?

import React from ‘react’;

A

It holds everything related to React that we need into the file.

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

How would you import a logo in a create-react-app app?

A

import logo from ‘./logo.svg’;

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

How would you import the CSS in a create-react-app app?

A

import ‘./App.css’;

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

What can you see in the index.js file in a create-react-app app?

A

We import the App function and using the ReactDOM library, render it to the DOM.

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

What does this line of code do?

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

A

The ReactDOM library calls render and looks on the document object for an element with an id of ‘root’ and replaces it with our ‘App’ function.

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

Where is the div with an id of ‘root’ located?

A

In the index.html file in the public folder.

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

What is the entry way of out application?

A

The div with an id of ‘root’.

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

What is good about create-react-app?

A

If we make any changes to any of the files it will automatically update inside of out local host.

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

19.

A

R

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

How do you open up the terminal in VSCode?

A

Terminal > New Terminal

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

What is the shortcut of opening a terminal in VSCode?

A

Something.

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

What should you do when you open a terminal inside of VSCode?

A

Make sure you’re inside the project.

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

What happened if you run yarn start in the VSCode terminal and nothing happens?

A

You may not have yarn installed on your computer.

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

What do package managers do?

A

Automate the process of installing, upgrading, configuring or removing any libraries we want.

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

What happens when you successfully start your app in the VSCode terminal but noting happens?

A

Just manually go to localhost:3000 in the browser.

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

What will happens when you run npm build?

A

You get a build folder. It says it’s creating an optimized production build.

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

What is a good thing about create-react-app?

A

It optimizes the code for you.

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

What is inside the build folder?

A

A minified index.html file, a static folder which contain our minified css files, our minified JavaScript files. All the code that we wrote in the src folder has now been created into optimized build files.

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

What would we do with the build folder?

A

Put it on a server.

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

What does Babel allow for us?

A

First Babel is going to take all the JavaScript files with the weird React syntax and make sure they work on all browsers no matter what version (how old or new (similar to what jQuery used to do))

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

What is webpack?

A

A modular bundler.

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

What does webpack do?

A

It allows us to write modular code.

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

What is meant when we say webpack allows us to write modular code?

A

The build folder only contains a few JavaScript files even though we have many in the src folder.

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

How many JavaScript files will webpack create?

A

Three. (Is this right?)

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

What are some of the JavaScript files in the build folder?

A

The main…..chunk.js JavaScript file

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

What type of tool is create-react-app?

A

A cli.

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

What is a cli?

A

A command line interface.

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

What will we use to deploy our application?

A

The build folder.

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

What is the purpose of package.json?

A

It allows us to have this package manager so, as React is all about a component architecture meaning we can use other peoples code in other components, we can use package.json to install other (perhaps) React components.

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

Give an example of how you would

A

If you go to material-UI, you can install component library material-UI.

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

How can you install material-UI?

A

By running npm install @material-ui/core@next.

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

What happens when we install material-UI?

A

It gets added to out package.json file.

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

What is React doing underneath the hood?

A

If you go to the index.html file in the public folder, you have some pre set up code. The key thingis when you look at the body tag, the only thing we have is a div with in id of root?

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

Where are we going to inject our React application?

A

In the div with an id of root in the index.html file of the src folder.

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

What happens if you put a, for example, h1 tag with text below the div with an id of root?

A

It will render to the screen which means the app will be part React and part HTML.

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

Why is being able to put other html tags in the index.html file useful?

A

Because it means you can inject React into parts of an application if desired.

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

What will you see if you inspect the React app (which has some HTML underneath) and go to the elements tab, what will you see?

A

The app is inside the div with an id of root and contains just HTML tags.

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

What happens if you open up the React developer tools?

A

The developer tools notice our React app. It has an app component that it’s created for us, but at the end of the day it’s the same thing as the html we see in the Elements tab.

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

What does the react library import do?

A

Allows us to write HTML like syntax inside a JavaScript file.

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

What does the react-dom library import do?

A

Imports the react-dom. A robot that interacts with the DOM.

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

What is the React package?

A

It allows us to write JSX, build components and build the VirtualDOM.

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

What is the ReactDOM?

A

A little robot that interacts with the DOM.

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

What does ReactDOM.render allow us to do?

A

Grab an element from HTML and insert < App / > into it.

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

20.

A

D

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

What happens when you eject a create-react-app?

A

It gives you two folders called scripts and config.

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

What is in the config (and scripts?) folder?

A

Everything the create-react-app was hiding under the hood for us.

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

What are some of the things in the config folder?

A
A jest folder for tests.
The webpack configuration (our module bundler).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
135
Q

What are some of the things in the scripts folder?

A

All the scripts that were run e.g. the build script.

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

Why is it recommended not to inject?

A

Because it reveals a lot of code and your code isn’t going to be better than the developers.

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

What are you ensuring when you use create-react-app?

A

We’re automatically getting the best system and project build out of the box.

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

What happens to create-react-app when there are updates or the industry changes?

A

create-react-app will update to reflect those updates/changes.

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

Why is ejecting not a good idea?

A

Because you lose all the benefits as create-react-app gets updates.

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

21.

A

C

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

How could you return JSX?

A

By writing a function or a class that returns it.

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

Why would you want to use a class to return JSX?

A

Because React has given us the ability to write classes that have a lot more functionality on them versus a function that returns JSX.

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

Whats the first thing you do when writing a class?

A

import component from React.

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

Show how you would import component from React.

A

import React, { component } from ‘react’;

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

How could you convert this function to a class?

function App () {
    return (
        < div className='App' >
            < p > Hello World < p / >
        < div / >
    );
}
A
class App extends component {
    render() {
        return (
        < div className='App' >
            < p > Hello World < p / >
        < div / >
        );
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
146
Q

What do we get access to when we use a class/the component?

A

The render() method.

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

What is this code block referred to?

function App () {
    return (
        < div className='App' >
            < p > Hello World < p / >
        < div / >
    );
}
A

A functional app/(component?)

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

Why would you want to use a class instead of a class?

A

By using a class component we get access to state.

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

What is state?

A

It’s a JavaScript object with properties that we can access at any point inside of our class.

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

How would we access state inside of a class?

A

You would call the constructor() keyword. Inside of the constructor you would call super().

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

What does super() do?

A

It calls the constructor method on the Component class.

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

What does calling the constructor method on the Component class from super() give you access to?

A

It gives us access to this.state

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

Where does the state property in this code live?

class App extends component {
    constructor() {
        super();
        this.state = {
            string: 'Hello World'
        }
    }
    render() {
        return (
        < div className='App' >
            < p > Hello World < p / >
        < div / >
        );
    }
}
A

On our class App

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

Show how you would create a state property on this code and set it to something.

class App extends component {
    constructor() {
        super();
    }
    render() {
        return (
        < div className='App' >
            < p > Hello World < p / >
        < div / >
        );
    }
}
A
class App extends component {
    constructor() {
        super();
        this.state = {
            string: 'Hello World'
        }
    }
    render() {
        return (
        < div className='App' >
            < p > Hello World < p / >
        < div / >
        );
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
155
Q

How would you render the string property living on the state object in this code?

class App extends component {
    constructor() {
        super();
        this.state = {
            string: 'Hello World'
        }
    }
    render() {
        return (
        < div className='App' >
            < p > Hello World < p / >
        < div / >
        );
    }
}
A
class App extends component {
    constructor() {
        super();
        this.state = {
            string: 'Hello World'
        }
    }
    render() {
        return (
        < div className='App' >
            < p > { this.state.string } < p / >
        < div / >
        );
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
156
Q

How would you render the string property living on the state object in this code?

class App extends component {
    constructor() {
        super();
        this.state = {
            string: 'Hello World'
        }
    }
    render() {
        return (
        < div className='App' >
            < p > Hello World < p / >
        < div / >
        );
    }
}
A

By using curly braces

class App extends component {
    constructor() {
        super();
        this.state = {
            string: 'Hello World'
        }
    }
    render() {
        return (
        < div className='App' >
            < p > { this.state.string } < p / >
        < div / >
        );
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
157
Q

What does the curly braces between the p tags do in this code?

A

It tells the HTML that anything between them is going to be JavaScript.

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

Why is it useful to use state to render text as opposed to using a static string?

A

Because you can use it as many times as you want and you only have to update in one place.

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

How would you change the value in state?

A

By using a method called setState()

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

Where does setState() come from

A

The Component that’s extended from the class App.

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

What does setState() do?

A

It lets us modify the state object.

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

Where would you get access to the (method?)/property onClick?

A

On every HTML element.

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

What does onClick take?

A

A function.

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

What happens to the function taken by onClick?

A

It gets called whenever the element gets clicked.

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

How would you create a button that when clicked changes the state object?

A

< button onClick={() => this.setState({ string: ‘Qwerty’ })} >
Change Text
< button / >

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

What does setState() take?

A

An object with all of the properties that you want to change on your state as well as their new values.

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

22.

A

T

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

How did older version of create-react-app start the app?

A

With a class instead of a function.

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

What are some of the syntax changes in JSX?

A

className (to give something a HTML class) instead of class(which create a class).
Curly braces which when used inside JSX means anything inside of them is a JavaScript expression.
Using onClick instead of onclick.

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

Why is there some syntax changes in JSX?

A

Because it’s JavaScript and it would get confused if we for example used class instead of className.

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

What would happen if you hover over className in JSX?

A

A popup would appear telling you it’s a JSX attribute.

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

Why do we use className instead of class in JSX

A

To distinguish between the two as class means something else in JavaScript.

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

What does class mean in JavaScript?

A

We’re creating a class.

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

What does class mean in HTML?

A

We’re giving something in HTML a class.

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

What type of function is used in onClick?

< button onClick={() => this.setState({ string: ‘Qwerty’ })} >
Change Text
< button / >

A

An anonymous function.

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

What is noteworthy about this code?

< button onClick={() => this.setState({ string: ‘Qwerty’ })} >
Change Text
< button / >

A

We don’t actually modify this.setState/state directly.

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

Why don’t we modify state directly?

A

It comes from the idea of a unidirectional data flow.

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

Why are you not allowed to modify state without calling the setState method?

A

Because anytime we change the state (e.g. a user click the button to change the state to a new string), when that click happens React actually intercepts (as React is the one talking to the DOM) the click and it reports back saying ‘I just got a click on the DOM, what do I do?’. In this case we say when the click happens I want you to update the state. But we’re not going to modify the state automatically, I’m going to say a click happened, state gets updated using setState and that change is going to re-render the component so we can go through this flow again.

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

Do components get re-rendered automatically if we modify state directly?

A

q

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

q

A

q

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

q

A

q

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

q

A

q

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

q

A

q

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

q

A

q

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

What happens when setState gets called in this code?

render() {
        return (
        < div className='App' >
            < button onClick={() => this.setState({ string: 'Qwerty' })} >
                Change Text
            < button / >
        < div / >
        );
    }
A

The render() method is going to run again.

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

Why does the render() method run again when setState gets called?

A

Because the state just got update (this is the declarative approach of React).

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

What happens when you hover over onClick?

A

A popup will show saying it’s a JSX attribute and not HTML.

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

Why do we use onClick in JSX and not onclick?

A

Because it isn’t HTML. It’s JavaScript mimicking HTML and in JavaScript we use camel case.

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

Can we use any HTML attributes we want in React like src, class and onclick?

A

Yes but sometimes there are differences. src for example is the same but onclick and class become onClick and className respectively.

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

What’s the key thing to remember with JSX?

A

That it’s trying to mimic what HTML does so we can create that VirtualDOM and break down each part of the app into components that keep getting re-renderd as we update the state using setState.

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

23.

A

D

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

How would you render a bunch of h1 tags with the name of these monsters?

class App extends component {
    constructor() {
        super();
        this.state = {
            monsters: [
                {
                    name: 'monster 1'
                },
                {
                    name: 'monster 2'
                },
                {
                    name: 'monster 3'
                },
            ]
        }
    }
    render() {
        return (
        < div className='App' >
        < div / >
        );
    }
}
A
class App extends component {
    constructor() {
        super();
        this.state = {
            monsters: [
                {
                    name: 'monster 1'
                },
                {
                    name: 'monster 2'
                },
                {
                    name: 'monster 3'
                },
            ]
        }
    }
    render() {
        return (
        < div className='App' >
            {this.state.monsters.map(monster => (
                < h1 >{ monster.name }< h1 />
            ))}
        < div / >
        );
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
193
Q

Why would you use curly braces in the div with a className of App?

A

Because we have to render JavaScript.

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

What does .map do?

A

Returns us the return of whatever function we pass to it, iterated over every element in an array.

195
Q

What does map take?

A

A function where the first argument is going to be the actual element that this function is going to get called on.

196
Q

What is usually returned when you call map?

A

A new array, but React is smart enough to know if we’re rendering off a bunch of HTML blocks in an array it will just display those elements.

197
Q

What warning would you get if you open up the console?

class App extends component {
    constructor() {
        super();
        this.state = {
            monsters: [
                {
                    name: 'monster 1'
                },
                {
                    name: 'monster 2'
                },
                {
                    name: 'monster 3'
                },
            ]
        }
    }
    render() {
        return (
        < div className='App' >
            {this.state.monsters.map(monster => (
                < h1 >{ monster.name }< h1 />
            ))}
        < div / >
        );
    }
}
A

Each child in a list should have a unique “key” prop.

198
Q

What is this error message asking?

Each child in a list should have a unique “key” prop.

A

Add a unique key to every child that gets returned out of the map.

199
Q

How would you fix the code?

class App extends component {
    constructor() {
        super();
        this.state = {
            monsters: [
                {
                    name: 'monster 1'
                },
                {
                    name: 'monster 2'
                },
                {
                    name: 'monster 3'
                },
            ]
        }
    }
    render() {
        return (
        < div className='App' >
            {this.state.monsters.map(monster => (
                < h1 >{ monster.name }< h1 />
            ))}
        < div / >
        );
    }
}
A

Any random unique string will work.

class App extends component {
    constructor() {
        super();
        this.state = {
            monsters: [
                {
                    name: 'monster 1',
                    id: 'monster1'
                },
                {
                    name: 'monster 2'
                    id: 'monster2'
                },
                {
                    name: 'monster 3'
                    id: 'monster3'
                },
            ]
        }
    }
    render() {
        return (
        < div className='App' >
            {this.state.monsters.map(monster => (
                < h1 key={monster.id} >{ monster.name }< h1 />
            ))}
        < div / >
        );
    }
}
200
Q

Why do we want a unique key?

A

Because React needs to know what element it needs to update if one of the elements in our array has a value that changes.

201
Q

Why are unique keys import?

A

It helps React know which element is the one that’s been updated. If someone does something that changes the state on the first object, React is smart enough to know that it only needs to update the first h1 tag. It doesn’t have to re-render everything which can be performant heavy.

202
Q

q

A

q

203
Q

q

A

q

204
Q

24.

A

O

205
Q

What’s a good rule of thumb when as to when to use the key attribute?

A

Anytime you use the map() function inside of render, or you have a list of the same jsx elements one after another, they need a key attribute

206
Q

What will happen if you don’t use the key attribute when you should?

A

CRA will warn you about it if.

207
Q

25.

A

S

208
Q

What is Component apart of?

A

The React library.

209
Q

What are we using in this line of code?

import React, { Component } from ‘react’;

A

Destructuring.

210
Q

How could you use Component if you didn’t destructure it like this?

import React from ‘react’;

A

class App extends React.Component {}

211
Q

What is Component?

A

A property on React.

212
Q

What happens when we do something like:

class App extends React.Component {}

A

We’re saying I want whatever functionality the React.Component (that was already build into the library by somebody) has and I want to add onto it.

213
Q

What’s an example of some functionality of React.Component?

A

The render() method comes built in with React.Component as well as some other things we can use. lifecycle methods are important methods that are on React.Component already.

214
Q

What was the advantage of SPA’s?

A

Because we have a tiny HTML page (with id of root) and a larger JavaScript file (with our React library, components, logic etc) that means we don’t have to communicate back and forth with server because React will re-render the DOM with information in the JavaScript file.

215
Q

Whats changed with SPA’s?

A

Instead of requesting a page it’s turned more into requesting for data.

216
Q

Is our server the only one we communicate with?

A

No, you can communicate with other servers/API’s that you don’t control.

217
Q

What are some examples of communicating with servers we don’t control.

A

The Google Fire base store or some different API endpoints.

218
Q

How would you communicate and receive data from third party API’s/servers?

A

With JavaScript.

219
Q

How could you get some JSON placeholder?

A

By visiting the website https://jasonplaceholder.typicode.com/users

220
Q

Whats is https://jasonplaceholder.typicode.com/users doing?

A

Providing an API, a way for us to access information from their server.

221
Q

How can you check https://jasonplaceholder.typicode.com/users

A

Open up the developer tools, click on the Network and refresh the page. You’ll see you’ll have a users document.

222
Q

What happens when you click on users and response in the Network tab of the developer tools?

A

The response (in this case a JSON file).

223
Q

What will you find when you start building larger projects?

A

You’ll start talking to API’s and trying to get different data for your application.

224
Q

What can the endpoints/servers that we communicate to get data from be?

A

3rd party servers or your own server.

225
Q

What’s the takeaway with SPA’s?

A

The way we build applications now is very dynamic.

226
Q

Where do we typically get information from in a modern SPA?

A

Typically we don’t hard code all of the information into our files. Instead, when a user opens something we are communicating with outside servers.

227
Q

26.

A

F

228
Q

What is the more realistic approach when setting state?

A

To not hard code the information but instead get it from a back end (server/database).

229
Q

How do we get the app component to make a call to a server and then put that data into our state so our render function has access to it?

A

Before we got the render method by extending into Component. We also get a bunch of other methods that are called lifecycle methods. These are what we’ll use.

230
Q

What are lifecycle methods?

A

Methods that get called at different stages, automatically by React, of when this component gets rendered.

231
Q

What does componentDidMount() do?

A

When this component mounts, it calls whatever block of code we write inside of it.

232
Q

What is mounting?

A

When React puts our component on the page, it renders it onto the DOM for the first time.

233
Q

Show a simple example of using componentDidMount()

A

componentDidMount() {
code
}

234
Q

What do we want to do in the body of componentDidMount()

A

Use JavaScript’s native fetch, to fetch/make an api request to the url

235
Q

What does fetch return us?

A

A promise

236
Q

What does the promise do?

A

Gives us a response of the actual body of the response.

237
Q

Because you don’t know what the body of the response looks like what’s a good idea?

A

console.log it

238
Q

Show how you would log the body of the response from https://jasonplaceholder.typicode.com/users.

A
componentDidMount() {
    fetch('https://jasonplaceholder.typicode.com/users').then(response => 
        console.log(response)
    );
}
239
Q

What are some properties on the Response object?

A

body, header etc. but we don’t really need them.

240
Q

What’s the main thing we want in regards to the Response object?

A

The body but we want to format it in a way that our JavaScript understands.

241
Q

How would you format the response object in a way JavaScript can understand and log it to the console?

componentDidMount() {
    fetch('https://jasonplaceholder.typicode.com/users').then(response => 
        console.log(response)
    );
}
A

componentDidMount() {
fetch(‘https://jasonplaceholder.typicode.com/users’)
.then(response => response.json())
.then(users => console.log(users))
}

242
Q

What is .json()?

A

A method on the response object that will give us back that response in the JSON format.

243
Q

How does this new JSON format get returned to us as?

A

A new promise that we’ll now have as the body which will be the (users?) array.

244
Q

How can we set the state to equal the users array?

componentDidMount() {
fetch(‘https://jasonplaceholder.typicode.com/users’)
.then(response => response.json())
.then(users => console.log(users))
}

A

componentDidMount() {
fetch(‘https://jasonplaceholder.typicode.com/users’)
.then(response => response.json())
.then(users => this.setState({ monsters: users }))
}

245
Q

What do you want the initial state to be?

A

An empty array.

246
Q

Why do you want the initial state to be an empty array?

A

Because we don’t need to hard code it any more. We’re going to wait for our component to mount, and then we’re going to fetch all of our users and then we’re going to update our states monsters property with the new array of users.

247
Q

What’s another good thing about create-react-app?

A

It comes with linting.

248
Q

Why is it good that create-react-app comes with a linter?

A

We can be aware of writing and making our code clean.

249
Q

Summarize this code.

componentDidMount() {
fetch(‘https://jasonplaceholder.typicode.com/users’)
.then(response => response.json())
.then(users => this.setState({ monsters: users }))
}

A

We’re using the componentDidMount() lifecycle method that we have access to because of our class component. We are then fetching from the url, then taking the response and converting it into the JSON format that our JavaScript can understand and use. Then we’re taking the users that we got back from it and set our monsters to that array of users.

250
Q

27.

A

O

251
Q

28.

A

A

252
Q

How can you think of calling components???

A

As custom created HTML like elements(h1, div etc).

253
Q

How are components named?

A

Upper camel case.

254
Q

How can you think of div in JSX?

A

As pre built components???

255
Q

How many ways are there to create components?

A

2

256
Q

What are the types of components you can build?

A

A class component and a functional component.

257
Q

What do class and functional components have i common?

A

They return some sort of JSX.

258
Q

What’s a naming convention you could have when creating components?

A

You can name components in the components folder that contain JSX with a .jsx extension. This is being very explicit.

259
Q

What happens when you name a file with a .jsx extension?

A

You’ll get a React icon next to the name. You’ll also see JavaScript React in the bottom right hand corner of VSCode.

260
Q

What does the .jsx extension mean?

A

It’s JavaScript, but with the JSX syntax.

261
Q

What happens when you change a .jsx extension to a .js extension.

A

It’ll still work.

262
Q

What happens at the end of the day in a create-react-app app?

A

It takes everything through Webpack and babel and will convert any .jsx files into a JavaScript file.

263
Q

What’s another naming convention you could use?

A

With a period. e.g. card.component.jsx

264
Q

What happens under the hood with CSS files?

A

create-react-app combines everything. If you go to the build folder and navigate to the css folder you’ll see two files. A chunk css file with a .map and one massive css file.

265
Q

What is the .map in the css folder in the build folder?

A

A source map.

266
Q

What does the css source map help with?

A

Debugging code in production.

267
Q

What will happen to all the different css files in the src folder when we release to production?

A

They’ll be combined together.

268
Q

29.

A

C

269
Q

What is the goal in React?

A

To break up code into smaller reusable pieces that are only focused on one responsibility.

270
Q

Why is this a good naming conversion (specifically the component part)?

card-list.component.jsx

A

You can see right away what file it is.

271
Q

How can you import React?

A

import React from ‘react’;

272
Q

How would you export CardList?

CardList = () => {
}

A
export const CardList = () => {
}

NOTE: This is a functional component.

273
Q

What do components take in?

A

props.

274
Q

What is props going to be?

A

The parameter we get from our functional component.

275
Q

How would you add props to this code?

export const CardList = () => {
}
A
export const CardList = (props) => {
}
276
Q

log props to the console:

export const CardList = (props) => {
}
A
export const CardList = (props) => {
    console.log(props)
    return (< div >< /div >)
}
277
Q

How would you import CardList into the app file?

A

import { CardList } from ‘./components/card-list/card-list.component’;

278
Q

How would you call CardList in App.js?

A

< CardList / >

279
Q

What is the props parameter?

A

Any parameter that we pass into < CardList / >

280
Q

Give < CardList / > an example prop.

A

< CardList name=”John” / >

281
Q

What will we log out if we console.log this code?

< CardList name=”John” / >

A

An object that says {name: “John”}.

NOTE: Any prop is going to be an object of any properties that you write onto a component where it gets used.

282
Q

What do you generally want when passing props?

A

For the props we’re passing in to match the parameters that we’re going to use inside the component.

283
Q

What is one of the main properties we have access to on props object?

A

children.

284
Q

Will the children property always be present on the props object?

A

Yes, but if there isn’t any children it’ll be Null.

285
Q

What are children on props object?

A

children are what you pass in between the brackets of our component that gets called.

286
Q

How would you convert this component to have children?

< CardList name=”John” / >

A

< CardList name=”John” >
< h1 >Qwerty< / h1 >
< / CardList >

287
Q

What will the children prop be in this code?

< CardList name=”John” >
< h1 >Qwerty< / h1 >
< / CardList >

A

< h1 >Qwerty< / h1 >

288
Q

How could you render children?

< CardList name=”John” >
< h1 >Qwerty< / h1 >
< / CardList >

export const CardList = (props) => {
    console.log(props)
    return (< div >< /div >)
}
A
export const CardList = (props) => {
    console.log(props)
    return (< div >{props.children}< /div >)
}
289
Q

Where else do you have access to props made in the App component?

A

On the App component itself.

290
Q

How can you get access to the props you created in the render (method?) of the App component.

A

With the this keyword. It gets attached to our actual class as a property called props. i.e. if you wanted to access it you would use this.props

291
Q

How would you import styles into card-list.component.jsx?

A

import ‘./card-list.styles.css’;

292
Q

How would you apply styles to the div here?

export const CardList = (props) => {
    return < div >{props.children}< /div >;
}
A
export const CardList = (props) => {
    return < div className='card-list' >{props.children}< /div >;
}
293
Q

Instead of passing Qwerty in as the children prop how would you .map though a list?

< div className="App" >
    < CardList name="John" > 
        < h1 >Qwerty< / h1 >
    < / CardList >
< / div >
A

< div className=”App” >
< CardList name=”John” >
{this.state.monster.map(monster => (
< h1 key={monster.id} > {monsters.name} < / h1 >
))}
< / CardList >
< / div >

294
Q

What is happening with this code?

< div className=”App” >
< CardList name=”John” >
{this.state.monster.map(monster => (
< h1 key={monster.id} > {monsters.name} < / h1 >
))}
< / CardList >
< / div >

export const CardList = (props) => {
    return < div className='card-list' >{props.children}< /div >;
}
A

The .map is going to generate a list of h1’s and put it as the children in between the div returned from the CardList component.

295
Q

What is a fundamental thing of React?

A

We’re building components that only care about one thing. For example, the CardList component only cares about displaying cards inside of it in some form/configuration.

296
Q

30.

A

C

297
Q

Why is this not good form?

< div className=”App” >
< CardList name=”John” >
{this.state.monster.map(monster => (
< h1 key={monster.id} > {monsters.name} < / h1 >
))}
< / CardList >
< / div >

export const CardList = (props) => {
    return < div className='card-list' >{props.children}< /div >;
}
A

Because our app component is the one responsible for mapping over the list of monsters and creating those elements. But we want to give that responsibility to the CardList component.

298
Q

Why do we want to give the responsibility of mapping over the list of monsters and creating those elements to the CardList component?

A

Because the Card list component should be the one responsible for listing the cards.

299
Q

How can you move the code responsible for listing the cards into the CardList component?

< div className=”App” >
< CardList >
{this.state.monster.map(monster => (
< h1 key={monster.id} > {monsters.name} < / h1 >
))}
< / CardList >
< / div >

export const CardList = (props) => {
    return < div className='card-list' >{props.children}< /div >;
}
A

By passing in the monsters as a prop from our app component and then move the .map into the card list.

300
Q

Show how you would pass in the monsters as a prop from our app component and then move the .map into the card list.

< div className=”App” >
< CardList >
{this.state.monster.map(monster => (
< h1 key={monster.id} > {monsters.name} < / h1 >
))}
< / CardList >
< / div >

export const CardList = (props) => {
    return < div className='card-list' >{props.children}< /div >;
}
A

< div className=”App” >
< CardList monsters={this.state.monsters} />
< / div >

export const CardList = (props) => (
    < div className='card-list' >
        {props.monster.map(monster => (
            < h1 key={monster.id} > {monsters.name} < / h1 >
        ))}
    < /div >;
)
301
Q

Why is this code good form?

< div className=”App” >
< CardList monsters={this.state.monsters} />
< / div >

export const CardList = (props) => (
    < div className='card-list' >
        {props.monsters.map(monster => (
            < h1 key={monster.id} > {monster.name} < / h1 >
        ))}
    < /div >;
)
A

Because our app doesn’t have to worry about creating those monster cards. The CardList component is the one responsible for that.

302
Q

What is something the card list component should not be responsible for?

A

Deciding how the component will look.

303
Q

Show how you would set up Card in a basic form and edit the CardList component.

export const CardList = (props) => (
    < div className='card-list' >
        {props.monsters.map(monster => (
            < h1 key={monster.id} > {monster.name} < / h1 >
        ))}
    < /div >;
);
A

import React from ‘react’;

export const Card = (props) => (
    < div >
        < h1 > {props.monster.name} < / h1 >
    < / div >
)

NOTE: This is a functional component.

import { Card } from ‘../card/card.component’;

export const CardList = (props) => (
    < div className='card-list' >
        {props.monsters.map(monster => (
            < Card key={monster.id} monster={monster} / >
        ))}
    < /div >;
);
304
Q

Why does the key still live on the CardList component?

A

Because we want React to be aware that if any of the monsters update we only want that one element to update that gets affected.

305
Q

How would you add styling to the Card component?

export const Card = (props) => (
    < div >
        < h1 > {props.monster.name} < / h1 >
    < / div >
)
A

import ‘./card.styles.css’;

export const Card = (props) => (
    < div className="card-container" >
        < h1 > {props.monster.name} < / h1 >
    < / div >
)
306
Q

Where can we get images?

A

From a website called https://robohash.org

307
Q

How could you add an image from robohash to the Card component?

export const Card = (props) => (
    < div className="card-container" >
        < h1 > {props.monster.name} < / h1 >
    < / div >
)
A

export const Card = (props) => (
< div className=”card-container” >
< img alt =”monster” src ={https://robohash.org /${props.monster.id}?set=set2} / >
< h1 > {props.monster.name} < / h1 >
< / div >
)

308
Q

What is the ?set=set2 of this code code?

< img alt =”monster” src ={https://robohash.org /${props.monster.id}?set=set2} / >

A

A url parameter.

309
Q

How can you add a size parameter to the url paramater?

< img alt =”monster” src ={https://robohash.org /${props.monster.id}?set=set2} / >

A

< img alt =”monster” src ={https://robohash.org /${props.monster.id}?set=set2&amp;size=180x180} / >

310
Q

How could you add an email to this code?

export const Card = (props) => (
< div className=”card-container” >
< img alt =”monster” src ={https://robohash.org /${props.monster.id}?set=set2} / >
< h2 > {props.monster.name} < / h2 >
< / div >
)

A

export const Card = (props) => (
< div className=”card-container” >
< img alt =”monster” src ={https://robohash.org /${props.monster.id}?set=set2} / >
< h2 > {props.monster.name} < / h2 >
< p > {props.monster.email} < / p >
< / div >
)

311
Q

31.

A

E

312
Q

Why do you break code up into multiple components and not have one big file?

A

With component architecture components can be placed and used in multiple locations. They are also more flexible.

313
Q

Show how components are more flexible.

A

The CardList component that renders Card components can be passed different properties. e.g. instead of monsters, it can be passed aliens. Therefore, the CardList component can be used on a different project or a different part of the app because it doesn’t care what it prints out.

314
Q

What do most good React projects do?

A

Break things down to small component file that the name tells you what it does.

315
Q

What happens the bigger a file gets?

A

The more JSX we have, the more logic we have, the harder it gets to be used in another place.

316
Q

What’s another benefit of breaking an app down into smaller components?

A

We have the flexibility of performance improvement potentially as well as having components that are really easy to test.

317
Q

Why are components easier to test if they’re small?

A

Because they’re so simple.

318
Q

What’s the key thing to remember about why we break things down into smaller components?

A

We combine each component with it’s concern. That concern is that this CardList is only concerned about CardList. Card is only concerned about cards.

319
Q

32.

A

S

320
Q

What is the current structure of the site?

A

The parent App component currently surrounds everything. This is where the state lives which gets passed down to the CardList component as an attribute (similar to an HTML attribute). CardList then receives it as a prop.

321
Q

What does the state get turned into when we pass it down as an attribute?

A

props into all the little components below in in the heiracy (if they are passed in as an attribute.)

322
Q

What does the state get turned into when we pass it down as an attribute?

A

props into all the little components below in in the heiracy (if they are passed in as an attribute.)

323
Q

Where can you view the (component?) state and props in a React app?

A

In the React developer tools.

324
Q

Where can you view the key in a React app?

A

In the React developer tools.

325
Q

What is the key used for in React?

A

To distinguish when multiple components of the same kind are rendered one after the other.

326
Q

What does React use if one of the Card components change?

A

React uses the key attribute to say ‘key three changed, do a quick render’. React makes sure that when React updates the DOM it’s going to be efficient and only update that one element, instead of all of them.

327
Q

What is the React developer tools useful for?

A

To see how information is being passed down.

328
Q

Where can you put state?

A

Wherever we want.

329
Q

What happens when the state changes, for example, lets say the monsters goes from 10 users to 20?

A

A state change that happens with setstate, from here we announce to whoever cares that the monster array has changed. Whichever component has those monsters passed down to is going to say ‘I received new props’, so I have to re-render. This component says hey I have new props information who needs it’. Whoever needs it gets passed down that prop information.

330
Q

How can you think of this?

A

As a function call to render (each component at the end of the day is a function that renders). If state changes it notifies the component underneath and say hey run the render function again, and so on.

331
Q

What happens when we talk about where state lives and how we pass down props what can be see?

A

That there are performance implications.

332
Q

Why are there performance implications when we talk about where state lives and how we pass down props what can be see?

A

Because every time state changes we’re going to have to rerun functions, because the properties or the inputs of these functions change.

333
Q

What have we done up to this point?

A

Have an API call to get the users when we initially load the page with our JavaScript, CSS and HTML file. create-react-app just simulates when we run it a fact server that sends these files. We get the users then gets each image of our monsters from another API, the robohash.

334
Q

What should we remember about the robohash that we’re using?

A

It’s an API which is the same as the users data.

335
Q

33.

A

S

336
Q

What do we first need when building out the search functionality?

A

The HTML element that will represent the text input.

337
Q

What element will we use for our search box?

A

An < input / > HTML element.

338
Q

What are the < input / > HTML elements?

A

Basic text inputs.

339
Q

What happens when we put type on an < input / > HTML element?

A

We can give it a different string and that string will help us get some features in the input that we might want for different types of inputs
NOTE: This is a HTML property that all inputs have.

340
Q

What’s an example of a type of feature we might ant in an < input / >

A

If we use password, what ever we type will become hidden.

341
Q

What string are we going to give < input / >

A

search

342
Q

Show how you would put a type property search on the HTML < input / > element.

A

< input type=”search” / >

343
Q

What does the type property search give us on < input / >

A

The ability to put on placeholder.

344
Q

What does placeholder do?

A

It essentially puts a string there when we haven’t typed anything into the search field.

345
Q

Show how you would put placeholder on < input type=”search” / >

A

< input type=”search” placeholder=”Text” / >

346
Q

What do we need to do whenever the user types something into the input?

A

Hijack or take control of it.

347
Q

Why do we need to Hijack or take control of input whenever the user types something into it?

A

Because we want to store that string.

348
Q

Where do we want to store that string we get from the user typing something into the search input?

A

On our state.

349
Q

Why do we want to store the string we get from the user typing something into the search input on the state?

A

Because we’re able to use it in order to filter out our monsters.

350
Q

How can we store the string we get from the user typing something into the search input on the state?

A

We first need to add a field to our state that represents what that stored value will be.

351
Q

Show how you would add a field to our state that represents what that stored value will be when when the user types something into an input field.

A

this.state = {
monsters: [],
searchField: ‘’
}

352
Q

What method would come in handy after we add a field to our state that represents what that stored value will be when when the user types something into an input field.

A

We have access to a method on our input called onChange().

353
Q

What should we do after we add a field to our state that represents what that stored value will be when when the user types something into an input field.

A

setup onChange()

354
Q

What does onChange do?

A

It fire with this synthetic event which is essentially just an event in our browser, whenever the input is changed. So, whenever the user types or removes anything.

355
Q

What do we pass to onChange()?

A

A function

356
Q

Show how you would set up onChange() in this code in a basic way.

< input type=”search” placeholder=”Text” / >

A

< input type=”search” placeholder=”Text” onChange={e => console.log(e)} / >

357
Q

What does e represent in this code?

A

The synthetic event.

358
Q

What would log to the console in this code?

< input type=”search” placeholder=”Text” onChange={e => console.log(e)} / >

A

In the console in the browser you’ll notice whenever you type anything or remove anything in the input we’ll see the onChange() fire.

359
Q

What will we see on the synthetic event?

A

It’s a huge object.

360
Q

Why is there a huge object on the synthetic event?

A

Because it’s a native event that the browser uses to do all kinds of different things. It gives us a lot of control.

361
Q

What is the main thing we want to look at on the object of the synthetic event?

A

The ‘target’ value.

362
Q

What does the ‘get’ and ‘set’ next to the ‘target’ value mean?

A

That we can either get the value of ‘target’ or set it.

NOTE: In this case we only want to get the value.

363
Q

What will the ‘target’ value give us back?

A

The HTML element.

364
Q

How can we log the HTML element of ‘target’.

A

< input type=”search” placeholder=”Text” onChange={e => console.log(e.target)} / >

365
Q

What is meant by ‘target’ giving us the HTML element?

A

It’s the HTML element that fired the event?

5:00

366
Q

What will be logged to the console?

< input type=”search” placeholder=”Text” onChange={e => console.log(e.target)} / >

A

< input type=”search” placeholder=”Text” / >

367
Q

What happens if you hover over < input type=”search” placeholder=”Text” / > in the console?

A

It will show where that element is.

368
Q

What do we want off of this

< input type=”search” placeholder=”Text” / >

NOTE: This appears in the console.

A

The value.

369
Q

How would you get the value off of this:

< input type=”search” placeholder=”Text” / >

NOTE: This appears in the console.

A

< input type=”search” placeholder=”Text” onChange={e => console.log(e.target.value)} / >

370
Q

What is value in this code?

< input type=”search” placeholder=”Text” onChange={e => console.log(e.target.value)} / >

A

A property on the input that will give us the string value that it holds.
NOTE: As you type you can see it update.

371
Q

How are we going to store the value the user types in the search input on the state?

A

By using the value on e.target.value.

372
Q

How can we store the value of e.target.value?

A

By calling setState in onChange()

373
Q

Show how you can store the value in e.target.value in the store from this code.

< input type=”search” placeholder=”Text” onChange={e => console.log(e.target.value)} / >

A

< input type=”search” placeholder=”Text” onChange={e => this.setState({ searchField: e.target.value })} / >

374
Q

What would happen if you wrote this code?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

You would expect to see the state update in the console. However, even though the event is firing the searchField key is always one letter behind meaning the first letter we type, searchField isn’t updated.

375
Q

Why is the searchKey always updating one letter behind what the user types in this code?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

Because setState is an asynchronous function call.

376
Q

What is a synchronous action?

A

Something we can expect to happen almost immediately. It’s something that pretty much happens in JavaScript knows the amount of time it’ll take so JavaScript will wait for that thing to finish before it continues running the rest of the code afterwords

377
Q

What is an asynchronous action/event?

A

Something that actually takes an indefinite amount of time that JavaScript doesn’t know. So what it does is run the rest of the code after and when the asynchronous event finishes it then runs that finished event.

378
Q

Whats something to remember in this code?

this. setState({ searchField: e.target.value })
console. log(this.state)

A

That this.setState is actually not happening immediately when we would expect it to. The state will be updated with the value that we set but it’s not going to happen in the immediate sense we would expect it to

379
Q

How could you log the state?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

By using a solution React has given us which is the second argument that we pass to setState. It’s a callback
which runs after setState is finished. So after setState has updated our state it will run the function that we pass. Here, we can log to the console.

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value }, () => console.log(this.state))
}}
/ >

380
Q

What is the thing to remember with setState?

A

If we wanted to see or do something with our state right after we set it then we have to do it inside this second argument function that will get called right after setState.

381
Q

34.

A

R

382
Q

Is this HTML?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

NO, it’s JSX.

383
Q

What happens when the DOM changes or Reacts to a user input e.g. searching for a monster,

A

It’s going to say hey, there’s an event, somebody has just typed something into the input

384
Q

What does React do when someone has typed something into an input????? Change the question

A

NOTE: We don’t manually update the DOM. If that were the case we would be using the onchange event natively in our HTML.

385
Q

What are HTML events?

A

Just something the DOM gives us in order to interact with user events

386
Q

What does React have (a type of event?)?

A

Synthetic events.

387
Q

What are synthetic events?

A

When a DOM event happens because for example a user clicks or types something in an input the DOM onchange event is going to say hey something changed. React intercepts that and says oh something has changed let me tell my React app that something has happened. This is what a synthetic event is.

388
Q

What is a synthetic event?

A

It’s like a fake event that we pretend is a DOM event but it’s something that our React robot is telling us saying hey there was an event on the DOM what should we do.

389
Q

Where is the synthetic event in this code?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

the onChange

Notice that it’s camel case meaning it’s not HTML but a synthetic event.

390
Q

What is onChange in this code?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

A synthetic event.

391
Q

What is onChange used for in this code?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

To detect whenever that DOM event happens.

392
Q

What happens with onChange in this code?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

We receive that event because something has happened and then we update the state.

393
Q

What is something to remember about state?

A

It’s something that usually changes in our app due to a user action.

394
Q

What specifically happens in this code?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

The searchField is going to change.

395
Q

Why is the searchField going to change in this code?

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

Because somebody has typed into the text box.

396
Q

Why don’t we run the onChange function in this code? Here, all we’re doing is defining the function and not running it.

< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}}
/ >

A

We could extract the entire piece of code put it above the render (method?) (which will be done in a later video) because we’re not running it here. We’re just saying this is an anonymous function that gets triggered onChange. This is an important distinction because you would never run setState in render because it’s going to create some errors. (try calling setState in render). Because every time you call setState it re-renders ans every time you re-render it’s going to call setState which creates a loop. What we’re doing here is defining a function, not running it just letting them know hey onChange I want this to happen and React internally with this synthetic event is going to say hey anytime onChange happens it’s going to be an event, just run this function (e => {
this.setState({ searchField: e.target.value })
console.log(this.state)
}} ) (I think that’s the function).

The last part is the console.log which doesn’t get logged right away. That’s because once again React is smart. We’re not interacting with the DOM. What it’s going to say is when we do setState it’s going to say hey React bot we have some updates that we want to make to the DOM can you do it for us. And our little robot is going to say yes, but I know the best time to do that so let me handle it. Therefore, it doesn’t happen right away. What it does is it scheduales and batches work so if there are maybe multiple updates that need to be done then it can optamise that for us. That’s why React is good because it figures out for us the best time ans way to update the DOM we just tell it we want an update. It’s declarative. But we leave that internal working to the React bot that’s improving with new updates.

397
Q

q

A

q

398
Q

q

A

q

399
Q

q

A

q

400
Q

q

A

q

401
Q

q

A

q

402
Q

q

A

q

403
Q

q

A

q

404
Q

q

A

q

405
Q

q

A

q

406
Q

q

A

q

407
Q

q

A

q

408
Q

q

A

q

409
Q

q

A

q

410
Q

q

A

q

411
Q

q

A

q

412
Q

q

A

q

413
Q

q

A

q

414
Q

q

A

q

415
Q

q

A

q

416
Q

q

A

q

417
Q

35.

A

F

418
Q

How can we filter the monsters where the names that don’t match the field?

A

Now how we’ll do this is in the render.

419
Q

Why don’t we want to actually modify our state’s monster array?

A

Because we want to keep the raw data in case

somewhere in this component.

We need to use the base unmodified array

420
Q

What should we do instead of actually modifying our state’s monster array?

A

Make a new array using the .filter method.

421
Q

What concept should we use to make a new array using the DOT filter method?

A

Destructuring

422
Q

What is destructuring?

A

It allows us to do is pull properties off of an object and set them to constants that we put inside of it’s curly braces.

423
Q

What is the syntax for destructuring?

A

(const) (bracket notation(use the same property name that we want to set as the constant)) (=) (the actual object we want to destructure from)

We say const and then we put our bracket notation and here we’ll use the actual object we want a destructure from, (the state object is what we want to pull the properties off of). And what we want to do is use the same property name that we want to set as the constant.

So when we say monsters and search fields, we’ll be pulling off the search field value and the monster’s value off of our state object and setting them to constants called Monsters and searchField.

424
Q

Show how you would use destructuring in this code:

this.state = {
monsters = [],
searchField = ‘’
}

render() {
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={this.state.monsters} />
< / div >
);
}

A

render() {
const { monsters, searchFiled } = this.state;
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={this.state.monsters} />
< / div >
);
}

425
Q

What is this the equivalent of doing

const { monsters, searchFiled } = this.state;

A
const monsters = this.state.monsters;
const searchField =  this.state.searchField;
426
Q

Why do we want to destructure instead of doing this?

const monsters = this.state.monsters;
const searchField =  this.state.searchField;
A

It’s just an easier way and a quicker way for us to write this out.

427
Q

Now that we have our monsters and search field what will we do next?

A

Set a new const called filtered monsters that we will set as our monsters .filter (remember from our filter method we get back a new array based off of the function that we pass into it where we’ll get the monster that it’s currently iterating over)

and what we want to do is take the name call .toLowerCase on it and then we’ll call .includes. On this we’ll use our search field and we also want to lowercase it

428
Q

What is toLowerCase

A

A method on all strings that converts all the alphabetic characters in a string to lowercase

429
Q

Why do we want to call toLowerCAse in this code?

A

Because we don’t want our search to be case sensitive.

430
Q

What is .includes?

A

And what this includes method does is similar to our array method. It just checks whether or not the string value we pass inside of our includes is actually in the string that it’s being called on.

431
Q

What will be returned from includes?

A

includes just like the array method includes will return true or false based off of whether or not (monsters.name.toLowerCase()) includes the string we’re passing to it.

432
Q

Set up the filteredMonsters constant

render() {
const { monsters, searchFiled } = this.state;
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={this.state.monsters} />
< / div >
);
}

A

render() {
const { monsters, searchFiled } = this.state;
const filteredMonsters = monsters.fliter(monster =>
monster.name.toLowerCase().includes(searchField.toLowerCase())
);
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={this.state.monsters} />
< / div >
);
}

433
Q

What should we do to the CardList component?

render() {
const { monsters, searchFiled } = this.state;
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={this.state.monsters} />
< / div >
);
}

A

Instead of passing in our state of monsters we’ll just pass in our new filteredMonsters.

434
Q

Pass in filteredMonsters to the CardList component.

A

render() {
const { monsters, searchFiled } = this.state;
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={filteredMonsters} />
< / div >
);
}

435
Q

And now we see that as we type we’re filtering out the monsters that don’t have what we’ve typed in inside of their name now we’ll notice that our component is actually re rendering every time. Why is this?

A

Because when ever set state is called and the properties change react re-renders our component (it recalls the render method).

436
Q

What happens to our code when React re-renders our component?

A

Our filtered monsters method is actually getting called again.

437
Q

Why is it good that our filtered monsters method is actually getting called again every time React re-renders our component?

A

Because what we’ve done is we’ve triggered this setState when ever they’ve typed something in which in turn sets the state value of search field which then in turn causes our component to re render and recall the render method which then re filters out the monsters by calling our monsters .filter again setting a new array which it’ll then pass to our card list which then renders card lists.

And this way we’re able to just dynamically live update our card list based on what we’re typing in and this is what’s great about react is that react is able to take control of what to render what to re render in its views without us having to do all of the extensive calls of showing elements and hiding elements react is able to do so for us as long as we understand the rules.

438
Q

q

A

q

439
Q

q

A

q

440
Q

q

A

q

441
Q

q

A

q

442
Q

36.

A

O

443
Q

37.

A

S

444
Q

What might we want to do with the search component/ input?

A

To reuse it multiple times

445
Q

What can we notice about the input

render() {
const { monsters, searchFiled } = this.state;
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={filteredMonsters} />
< / div >
);
}

A

All it is is just an input that doesn’t need any local state even though it seems like we’re calling set state in our input.

446
Q

What is the input really?

A

It’s really just a function that we’re passing from the context of our app component into the onChange handler of our input.

447
Q

What does the fact that the input is really just a function that we’re passing from the context of our app component into the onChange handler of our input?

A

We can probably move this into its own component, so we can have a reusable search component.

448
Q

How will we make a reusable search component from the input?

A

Make a new component called search-box and we’ll create the usual file search-box.comonent.jsx

449
Q

Why do some our files have .jsx and some have .js?

A

Mentioned earlier, create-react-out hides away some of the configuration for webPack and babel. What babel does is it helps transpile down any of the modern JavaScript including JSX style files that we write into older versions of JavaScript in the public folder, when we finally run our build script inside of our scripts file. Now in this transform if we look at our .js file for App.js we actually says see that it says JavaScript babel down at the bottom. So even though we’re writing JSX code here, because we’re rendering HTML in our JavaScript, babel knows that it should probably run this regardless, through a JSX transform even though it’s not a .jsx file type.

But right now just know that whether or not you write .js or .jsx, in the context of create-react-app you can write jsx in both file types.

450
Q

q

A

But we want to write .jsx in ours because we want to be explicit.

We want to know that if we’re gonna write JSX, while this file type is JSX, we’re also going to create our search-box.styles.css

451
Q

What do you do when you write your CSS?

A

You want to import it into our search-box.component.jsx file.

452
Q

How would you import the CSS into the search-box.component.jsx file?

A

First import react from react.
And then import in our style sheet.

import ‘./search-box.styles.css’;

453
Q

What is a difference between functional and class based components?

A

Functional components unlike class components such as our app.js component, they don’t have access to state

454
Q

Why don’t functional components not have access to state?

A

Because they don’t have access to constructor.

455
Q

What is the constructor?

A

A class method on our component that we import from react that we extend our class from.

456
Q

What’s something else functional components don’t have access to?

A

lifecycle methods.

457
Q

Is it bad that functional components don’t have access to state or lifecycle methods?

A

No, because we don’t always need to use lifecycle methods or internal state. Sometimes all we want to do is render some HTML and that’s what a functional component really is.

458
Q

How could you define a functional component?

A

Unlike a class component a functional component is just a component that gets some props and returns some HTML.

459
Q

What’s the main thing (for now) to remember about functional components

A

If you don’t think you need internal state nor access to lifecycle methods then just use a functional component

460
Q

Why should you use a functional components and not a class component if you don’t need access to state or lifecycle methods?

A

Because it’s easier to read, it’s actually easier to test and it’s in some ways smaller and easier to reason about.

461
Q

How should we start writing the SearchBox functional component?

A

const SearchBox = () => {

}

462
Q

What show we do with the SearchBox component from here?

const SearchBox = () => {

}

A

Copy over the input that we want inside the SearchBox component.

463
Q

Show how you would copy over the input you want and put it in SearchBox

render() {
const { monsters, searchFiled } = this.state;
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={filteredMonsters} />
< / div >
);
}

const SearchBox = () => {

}

A
const SearchBox = () => {
   < input type="search" placeholder="Text" onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
464
Q

What should you apply to this code?

const SearchBox = () => {
   < input type="search" placeholder="Text" onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
A

A class name of search to it

465
Q

Why would you apply a class name of search to this code?

const SearchBox = () => {
   < input type="search" placeholder="Text" onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
A

Because that’s where our search-box.styles.css are applying those styles to. We’ll keep this type because we know that it’s going to be search.

466
Q

Apply a className to this code.

const SearchBox = () => {
   < input type="search" placeholder="Text" onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
A
const SearchBox = () => {
   < input 
      className="search"
      type="search" 
      placeholder="Text" 
      onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
467
Q

What would you probably want to do with the placeholder value in this code?

const SearchBox = () => {
   < input 
      className="search"
      type="search" 
      placeholder="Text" 
      onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
A

Set it dynamically.

468
Q

Why might you want to set the placeholder value in this code dynamically?

const SearchBox = () => {
   < input 
      className="search"
      type="search" 
      placeholder="Text" 
      onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
A

Maybe another place that wants to use searchBox doesn’t want the place holder to say search monsters. e.g. if they want to search people or anything else.

469
Q

What do we want placeholder to be?

A

A prop that gets passed in.

470
Q

How could we …..props redo question

A

We can destructure that prop off of the props object

471
Q

How can we destructure that prop off of the props object?

A

Because all the props come in as one big object.

472
Q

Destructure the props off the props object and then pass it into the placeholder.

const SearchBox = () => {
   < input 
      className="search"
      type="search" 
      placeholder="text" 
      onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
A
const SearchBox = ({ placeholder }) => {
   < input 
      className="search"
      type="search" 
      placeholder={placeholder} 
      onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
473
Q

What can onChange be in this code?

const SearchBox = ({ placeholder }) => {
   < input 
      className="search"
      type="search" 
      placeholder={placeholder} 
      onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
A

Another prop that gets passed in

474
Q

Make onChange a prop that gets passed in. This needs to be a function lled handleChange. Destructure handleChange aswell.

const SearchBox = ({ placeholder }) => {
   < input 
      className="search"
      type="search" 
      placeholder={placeholder} 
      onChange={e => {
          this.setState({ searchField: e.target.value })
          }} 
    / >
}
A
const SearchBox = ({ placeholder, handleChange }) => {
   < input 
      className="search"
      type="search" 
      placeholder={placeholder} 
      onChange={handleChange} 
    / >
}

Redo this part???????
5:34

475
Q

q

A

q

476
Q

q

A

q

477
Q

How would you export this code?

const SearchBox = ({ placeholder, handleChange }) => {
   < input 
      className="search"
      type="search" 
      placeholder={placeholder} 
      onChange={handleChange} 
    / >
}
A
export const SearchBox = ({ placeholder, handleChange }) => {
   < input 
      className="search"
      type="search" 
      placeholder={placeholder} 
      onChange={handleChange} 
    / >
}
478
Q

How would you import SearchBox?

A

import { SearchBox } from ‘./components/search-box/search-box.component’;

479
Q

How would you replace input with the SearchBox component?

render() {
const { monsters, searchFiled } = this.state;
return (
< div className=”app”>
< input type=”search” placeholder=”Text” onChange={e => {
this.setState({ searchField: e.target.value })
}}
/ >
< CardList monsters={filteredMonsters} />
< / div >
);
}

A
render() {
    const { monsters, searchFiled } = this.state; 
    return (
        < div className="app">
            < SearchBox
               placeholder="Text",
               handleChange={e => this.setState({ searchField: e.target.value })}
            / >
            < CardList monsters={filteredMonsters} />
        < / div >
    );
}
480
Q

What’s great about react?

A

The component driven style of writing code,

481
Q

What is our SearchBox

A

A presentational component

482
Q

What does our SearchBox component do?

A

Pretty much styles an input and then it takes any functionality that it might need in its handleChange property.

483
Q

Why is it great to we have a reusable SearchBox component?

A

We can minimize the amount of repeat code that we have. We don’t have to write an input and then style it inside of a local file because we can separate it into its own component.