An online markdown blog and knowledge repository.
What does 'contextual this' mean really (from the quiz)?
Why didn't I use the advice to 'Think Like a React Developer' while creating Lab06 yesterday? This would have prevented me from over-utilizing 'state' in the App Component.
Is a Java warm-up but was skipped due to time limitations.
class-07/warm-up.md
If a function returns a new value then the operation must be returned.
Don't overthink these, keep it simple.
When something is being passed-in to a function, the it is easy to simple concatenate something to the end.
GitIgnore: In VS Code, when a file is in the filesystem view and is not tracked, it's name will be greyed out.
In the case of City Explorer and LocationIQ, the 1st result (index '[0]') is most of the time the correct result.
Environment Variables in React:
let myApiKey = process.env.REACT_APP_CUSTOMNAME;
// or
let result = await axios.get('https://www.somedomain.net/v1/search.php?key=${process.env.REACT_APP_CUSTOMNAME}/etc');
React-Bootstrap: FormControl component is equivalent to html5 <input>
element.
Anonymous Inline Method: DO NOT use an anonymous function without a parameter, even inside an onEvent type in-line event registration will fire every time the render occurs.
In a React App when capturing user-inputs that will be submitted:
onChange(e)=>{setState{}}
onSubmit
is called it shoudl interrogate this.state.property to get the inputted value(s).React State: You cannot access state properties immediately after setting them with a setState code-block.
Bootstrap Form: When using a Submit type button, the onSubmit={callback}
must be defined in-line as a Form (property thing)
API Calls:
&format=json
When to use State vs Props vs a local variable? It's all in where you are going to use it.
String Methods:
Node: JS Runtime that is NOT in the browser.
NPM: Node Package Manager for installing Node packages.
Express.js: An NPM Package used to build a server.
Json Formatter: Add-on for Chrome, adds 'raw' and 'parsed' views to the window.
Node allows us to create a server.
For Code301 we will be team 'server.js' endpoint.
<pkg>
server.js
file..gitignore
and .eslintrc.json
from ./configs
to the root of the project..vscode
file, which can be added to .gitignore
.'use strict';
and console.log("hello world");
for simple proof-of-life.requires
section instead of import. This is a simple list of required somethings.use
section that will call the requires
items.routes
section to define endpoints.errors
section for error handlers.listen
section that will start the server..env
file and add PORT=3001
npm install dotenv
???let data =require('./{filepath}');
On the server, run npm -i express
Continue to configure the Express.js server:
'use strict';
console.log('ehlo');
const express = require('express'); // imports express.js
require('dotenv').config(); // grabs dotenv config file entries
const app = express(); // defines the app and executes it
const PORT = process.env.PORT || 3002; // usable because dotenv is installed and adds a fallback port if .env file cannot be read
app.listen(PORT, () => console.log('listening on ${PORT}')); // method built-in to Express to start the server takes a port and a callback method
// routes
// the slash route aka default route
app.get('/', (req, resp) => {
resp.send('ehlo from app.get');
}) // 2 params: url, callback
app.get('/sayHello', (req, resp) => {
resp.send(`Hello ${req.query.name}`);
})
app.get('*', (req, resp) => {
resp.send('this is not the url you are looking for.');
}) // the catch-all method should always be last
app.get('/pet', (req, resp, next) => {
try {
let species = req.query.species;
let result = data.find((item) => item.species === species); // works a lot like filter
resp.send(result);
}
catch (error) {
next(error);
} // will catch most if not all errors within the try block
}) // a handle pets route
// error handling
app.us((err, ?))
Stop: CTRL+C
Start: npm start
Every time a change is made to the code, the server must be stopped nad started.
OR just use NODEMON.
Listens for code changes and restarts the server automatically.
Install NodeMon globally with npm i -g nodemon
to use it on all applications on my dev workstation.
Then execute with nodemon
at the root of the server project.
To close an open (conflicting) port: npm kill-port {num}
Deploy back-end servers here!
REACT_APP_SERVER = http://localhost:3001
.let thingy = '${process.env.REACT_APP_SERVER}...'
.data
to get into the object response from an API.Cross Origin Resource Sharing. For example, a server at domainA.com makes an XMLHttpRequest to domainB.com/data.json.
Install CORS with npm i cors
Require CORS in server.js: const cors = require('cors');
Custom Servers with Node and Express.
Draw the WRRC with partner, timeboxed to 15 mins.
Move to building the server, and getting weather data, given a city name.
Note: For now get wx data by using just the search query without the Lat Lon parameters.
Create a class 'Forecast' to capture date and description data.
Note: NUKE THE SLASH when setting the server URL in any properties or environment variables.
Trigger Deploy: Required after changing Env Vars in Heroku (and Netlify I'm sure).
Aim to: Get the front-end and back-end correctly linked up.
Revelation: I need to do more planning before coding.
How can Sheyna help me?
My goals in this class include gaining proficiency in building interactive websites. I see this as an all-around useful skill to have, and learning React and interaction with APIs and Servers/Databases will only make it better and more valuable to my future.
One area of concern is (again) Canvas. Code Fellows should make sure the assignment text and goals are clear and up-to-date. This is a minor nit-pick and is non-blocking day to day so far.
Right now my top strength is my ability and willingness to help out my team members and make network connections. I don't know what clicked in my head but networking has become much easier in the last few weeks. Two months ago it was nearly impossible for me to reach out to strangers (or long-lost acquaintances) but I have since re-connected with two prior professional contacts, and reached out to several fellow students to get connected with them. The challenge for me now will be maintaining those links.
I think maintaining my professional links is one of the areas where I need to improve on. Figure out a way to promote my maintenance of these links, beyond immediate needs.
That's all for now.