Skip to content

Instantly share code, notes, and snippets.

View samuraijane's full-sized avatar

Matthew Day samuraijane

View GitHub Profile
@samuraijane
samuraijane / redux-101.md
Last active November 4, 2022 00:03
Redux 101 – An overview of managing global state

Redux 101

An overview of managing global state

  • When we talk about <1>, we mean variables that can be accessed throughout the application regardless of what the view may be
  • With React and its useState hook, state is managed locally– that is, the state variables are exposed only within the component where they are defined
  • As such, they are specifically tied the component's corresponding <2> in the browser
  • This type of architecture is known as <3>
  • The <4> means the data, as defined by the state of a variable or variables, available to the view
  • The <5> is the data that is rendered in the browser at a given point in time
  • And the <6> is the logic that decides if the model should change
@samuraijane
samuraijane / react-103.md
Last active September 19, 2022 10:56
React 103 – Props

React 103

React props are similar to the argument and parameter of a JavaScript function

A JavaScript function that takes one or more <1> is defined with the same number of <2>

// definition --> `name` is the <3>
function greeting(name) {
  return `Hello ${name}`;
}
@samuraijane
samuraijane / react-102.md
Last active September 19, 2022 10:57
React 102 – Managing state in React with `onClick`

React 102

Managing state in React with onClick

State

  • The term we use to refer to the value of some variable in <1> at a given moment in time is <2>
  • Understanding how and when state <3> is critical to becoming a strong developer
  • A hook is simply a <4> (before hooks, some developers would have called it a <5>)
  • All hooks in React are <6> exports so to import a React hook, <7> are necesary
  • Managing state requires a named <8> and a named <9> of your choice (the former holds a value while the latter sets the value)
  • The syntax includes a <10> on an <11>
@samuraijane
samuraijane / react-101.md
Last active September 18, 2022 18:45
React 101 – A brief introduction to React

React 101

A brief introduction to React

React

  • React is a <1> available at NPM
  • As such, any project built with React will have the file <2> even though React is used to write front-end code
  • A React project is built from separate <3> which keep the code compartmentalized
  • It was created and is maintained by developers at <4>
  • React uses a <5> to update the HTML DOM; your React code should not <6> the HTML DOM directly
  • React attaches itself to the DOM through the <7> which is located in src/index.js
@samuraijane
samuraijane / Common express methods
Last active August 20, 2022 02:50
Common express methods to handle client requests
# Server 102
## Common express methods to handle client requests
`.get`
Returns data to the client which the client has requested
URL
https://highonlife.com/members/328
REQUEST BODY
```json
null
// DEFINE AND EXPORT
// save this in a file named "greeting.js"
function greeting(name) {
return `Hello ${name}`;
}
module.exports = greeting;
// IMPORT AND USE
const greeting = require('./greeting.js');
@samuraijane
samuraijane / Core module example
Last active August 13, 2022 20:54
Core module example
const dns = require('node:dns');
const options = {
family: 6,
hints: dns.ADDRCONFIG | dns.V4MAPPED,
};
dns.lookup('google.com', options, (err, address, family) => {
console.log('address: %j family: IPv%s', address, family)
});
@samuraijane
samuraijane / Common libraries for bootcamp students
Last active August 17, 2022 21:00
Common libraries for bootcamp students
***
BCRYPT
`npm i bcrypt`
[npm Docs](https://www.npmjs.com/package/bcrypt)
Creates a hashed string from an input. Uses callbacks, not promises.
***
BODY PARSER – DO NOT USE (SEE NOTES BELOW)
`npm i body-parser`
const shoppingList = ['apples', 'biscuits', 'cabbage', 'dip'];
const isCode200 = () => Math.random() >= 0.5;
function getData() {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (isCode200()) {
resolve(shoppingList);
} else {
reject('There was a problem with the server, please try again.');