professorbrian.comprofessorbrian.com › et570 › et570m1_week10_notes.… · web viewthis is not...

13
Week 10 Notes related to React video instruction The Codevolution YouTube channel is here: https://github.com/gopinav I have downloaded and unzipped it to the hard drive on my home pc (W10). You may choose to save and unzip it wherever you choose as well as using different folder names than I chose to use. Below, I open the command prompt and issue cd commands (change directory) until the prompt reflects that I am in the desired folder.

Upload: others

Post on 04-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

Week 10 Notes related to React video instructionThe Codevolution YouTube channel is here: https://github.com/gopinav

I have downloaded and unzipped it to the hard drive on my home pc (W10).You may choose to save and unzip it wherever you choose as well as using different folder names than I chose to use.

Below, I open the command prompt and issue cd commands (change directory) until the prompt reflects that I am in the desired folder.

Page 2: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

In the Command Prompt window, locate the folder containing the project you want to work with.

Then issue the ‘npm install’ command followed by the ‘npm start’ command.

The files needed to launch will be located and the app will launch in port 3000 of the local computer.

Page 3: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

----------------------------- Chapter 3 Folder Structure --------------------------

React uses SPAs. Index.html will be served to the user’s browser.The views will change as the content gets modified by js files in the project.Typically, no edits/changes are required in the body of index.htmlThe js project files will “inject” code into the root div.The React app controls the UI in this way.

The src (source) folder is where developers spend most of their time.index.js is the first code to execute.

Page 4: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

The root component. App.js is identified as well as the Dom component, the root div.The app component is rendered inside the root DOM node.

Page 5: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

App.js is responsible for what is displayed in the browser.

----------------------------- Chapter 4 Components --------------------------

Page 6: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

At its simplest, a component is the code inside a .js file

Page 7: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

This ‘Hello world” app uses a class component. The App class has a render method which returns some HTML. A future chapter (6) will delve into class components in more detail.

--------------------------------- Chapter 5 Functional Components -----------------------------

Page 8: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

In the video, we can see which folders and files are being used.In this example it is Greet.js in the components folder (which is in the src folder etc…)On your computer, inside the files and folder you downloaded from GIT, find these files as they are presented in the tutorials.

Page 9: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

React Fundamentals\components-demo\src\components\Greet.js

Note 1: The function on lines 3 – 6 has been commented out and replaced with an arrow function on lines 7 – 16.Note 2: Greet that on line 18 is exported; additionally, we need to import it into App.jsSee line 4 below.

Page 10: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm
Page 11: professorbrian.comprofessorbrian.com › et570 › ET570m1_Week10_notes.… · Web viewThis is not unique to Create React App—it’s just how JS apps generally work in Node/npm

npm start follows npm build and runs the app in the development mode.It will open http://localhost:3000 to view it in the browser.

The page will refresh automatically without the need to reload if you make edits to App.js

A not uncommon error one encounters when using React:‘react-scripts' is not recognized as an internal or external command, operable program or batch file…

It is not enough to run npm start. You need to run npm install to get the dependencies to your machine first. This is not unique to Create React App—it’s just how JS apps generally work in Node/npm ecosystem.

package.json specifies the dependencies but doesn’t actually include the source code for them (sometimes they’re pretty large). So you need to run npm install in the project folder after cloning. After that, other commands will work too.-Source: https://github.com/facebook/create-react-app/issues/1627