Vocabulary: Model-View-Controller (MVC)

MVC (Model-View-Controller): MVC is a design pattern commonly used in software development to organize the structure of an application. It divides an application's components into three main parts: Model: The Model represents the data and …

Vocabulary: Call signature

A call signature in TypeScript is a way to define the type of a function or method within an interface or type. It specifies the shape of a function, including the parameter types and the return type. This allows you to describe the signat…

Vocabulary: Index signature

In TypeScript, an index signature (also known as an indexable type) allows you to define the types of properties that are not known in advance but can be accessed using square bracket notation. Index signatures are particularly useful when…

Vocabulary: Higher-Order Component (HOC)

A design pattern used in React that is a function that takes in a component and returns a new component. (getting all this from ChatGPT) import React from 'react'; function Greeting(props) { return <h1>Hello, {props.name}!</h1>; } export default Gr…

React: Generic Type

type ExampleComponentProps<T extends React.ReactElement> = { children: T; }; const ExampleComponent = <T extends React.ReactElement>({ children }: ExampleComponentProps<T>): React.ReactElement => { if ('onClick' in children.props) { console.log("children has an onClick prop"); } return <div>{childre…</div></t></t></t>

Testing Notes

-Unit Testing ・The testing of individual blocks of an application such as a class, function, or component. -Integration Testing ・Testing a combination of units and ensuring they work together. -E2E Testing ・Testing the entire applicatio…

Prettier & Eslint format

package.json "scripts": { "prettier": "prettier --write --ignore-path .gitignore './**/*.{js,jsx,ts,tsx,json}'", "lint": "eslint --fix . --ext js --ext jsx", "format": "eslint --fix . --ext js --ext jsx && prettier --write --ignore-path .g…

Preload image

useEffect(() => { setTimeout(() => { // preload const img = new Image(); img.src = image; // setLoaded to true on load and display image img.onload = () => { setLoaded(true); }; }, (idx + 1) * 300); }, []); ... loaded ? ( // display image )

React: Note on what happens during rendering and re-rendering

this is a note on what goes on when a component renders and re-renders notes are from watching React Render Tutorial - YouTube Rendering has 2 phases: Initial Render: Render phase: -start at root -goes down leaf components -use createEleme…

React: Simple context template

import React, { createContext, Dispatch, useContext, useReducer } from "react" const hogeData = {}; export const HogeContext = createContext<any>(hogeData) export const HogeDispatchContext = createContext<Dispatch<any>>(() => { }) export const HogeContextPro</dispatch<any></any>…

Regex: match one byte character and number

event.target.value.match(/^[A-Za-z0-9]+$/)

Javascript: Skip an element array and make a new array

var newArray = array.reduce(function(result, hoge) { if (some condition) { result.push(hoge); } return result; }, []); or var newArray = array.filter(function(hoge) { if (some condition) { return hoge; } });

React: Outside Click Detection

import React, { useRef, useEffect } from "react"; export default SomeFunctionComponent(props) { const elementRef = useRef(null); useEffect(() => { function handleOutsideClick(event) { if (ref.current && !ref.current.contains(event.target))…

React Context API examples

*context api example for me, myself, and i 2 ways to use context api with inital value hoge.contex.jsx import { createContext } from ‘react’ import HOGE_DATA from ‘./hoge.data.js’ // some data with values const HogeContext = createContext(…

CSS Note: Unit conversion from relative to pixels

Just a lil note on unit conversion from relative to pixels ・Each property has an itinital value if not declared or there is no inheritance ・Browsers specify a root font-size for each page(usually 16px ) ・Percentages and reltavie units a…

Creating repository for existing project on Github

A lil note on how to make a new repository on GitHub of an existing local project Create a new repository on GitHub. Open your terminal cd to the project you want to create on Github Initialize the local directory as a Git repository git i…

React Hook: useState Example

*useState notes for me, myself, and i use useState to add state to function components class component and function component comparison class component class Example extends React.Component { constructor() { super(); this.state = { displa…

Redux-Saga example

*redux-saga notes for me myself and i Redux-saga are for asynchronous actions with side-effects install npm i redux-saga root.reducer.js import { combineReducers } from 'redux'; import { persistReducer } from 'redux-persist'; import userRe…

TypeScript Basic Notes

*Some TypeScript notes for me, myself, and I Typescript adds types write cleaner code avoid unneccessary error install npm install --save-dev typescript compile .ts to .js command line: tsc hoge.js or command line: tsc hoge.ts --watch or t…

Redux Thunk

Redux Thunk middleware allows you to write action creators that return a function instead of an action. The thunk can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met. install npm install redux-…

Redux Persistor

*Saves redux state to local or session storages Local Storage ・Data is stored in tabs and windows ・The data will not expire. ・Data remains after browser restart Session Storage ・Data is stored in current tab only ・Data remains after b…

Redux Reselect

*to memoize state so that every time mapStateToProps is called it does not re-render components that do not need to be re-rendered Install reselect npm i reselect Create selectors hoge.selectors.js import { createSelector } from 'reselect'…

Redux Practice Example 3

Provider to index.js index.js import { Provider } from 'react-redux'; import { store } from './redux/store.js'; <Provider store={store}> <App /> </Provider>, Connect to components hoge.js *use the state or dispatch as props of the component const mapStateToProps = (state) => ({ ho…

Redux Practice Example 2

Creating ActionTypes hoge.types.js export const HogeActionTypes = { HOGE: 'HOGE', }; Creating Actions (for dispatching) hoge.actions.js import HogeActionTypes from './hoge.types.js'; export const hoge = () => ({ type: CartActionTypes.HOGE,…

Redux Practice Example

Installing Redux npm i redux redux-logger react-redux Creating store store.js import { createStore, applyMiddleware } from 'redux'; import logger from 'redux-logger'; import rootReducer from './root-reducer.js'; const middleWares = [logger…

Redux Notes

*redux notes Redux Redux Introduction ・state management ・get rid of all states in components ・put them in a store and pass the state to the component that needs it Why Redux ・Good for managing large state ・Useful for sharing data betw…

Routing Notes

*gibberish notes on routing Routing - React is just a UI library - Angular comes with routing (framework) - Before SPA had a problem with back button (url did not change) - Browser has History API - SPA routing libraries use history API to…

Sign in with Google Popup using Firebase

const provider = new firebase.auth.GoogleAuthProvider(); provider.setCustomParameters({ prompt: 'select_account' }); export const signInWithGoogle = () => auth.signInWithPopup(provider); - import { signInWithGoogle } from '../hoge/hoge/fir…

Adding SVG as React Component

- add hoge.svg in assets folder (if you have one) in react project - import { ReactComponent as Logo } from '..../assets/hoge.svg' - < Logo /> (use as component)

React Notes

*Just some gibberish notes I took about React The Birth of React * came out in 2013 * before there was JS, HTML, CSS * browsers worked differently so had to implement it on JS * JQuery worked through all browsers * BackBonejs organize big …