This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState, FormEvent } from 'react'; | |
type FormField = { | |
field: string; | |
errorMessage?: string; | |
hasError?: boolean; | |
required?: boolean; | |
value?: boolean | string | string[] | null; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"General": { | |
"Code": "AAPL", | |
"Type": "Common Stock", | |
"Name": "Apple Inc", | |
"Exchange": "NASDAQ", | |
"CurrencyCode": "USD", | |
"CurrencyName": "US Dollar", | |
"CurrencySymbol": "$", | |
"CountryName": "USA", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
React.useEffect( () => { | |
const abortCtrl = new AbortController(); | |
fetch( | |
`some_url`, | |
{ | |
method: "get", | |
headers: new Headers( { | |
"Content-Type": "application/json", | |
"Accept": "application/json", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from "fs"; | |
import path from "path"; | |
import matter from "gray-matter"; | |
import remark from "remark"; | |
import html from "remark-html"; | |
export type Product = { | |
id: string; | |
description: string; | |
price: number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useQuery } from "react-query"; | |
import axios from "axios"; | |
export type QueryResponse = { | |
[key: string]: string | |
}; | |
const getStuff = async ( | |
_: string, // TODO: Figure out what this arg is | |
searchQuery: string, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// useModal.ts | |
import React from "react"; | |
export const useModal = () => { | |
const [modalIsVisible, setModalIsVisible] = React.useState(false); | |
const toggleModalVisibility = () => setModalIsVisible(!modalIsVisible); | |
return { modalIsVisible, toggleModalVisibility }; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// useDebounce.ts | |
import React from "react"; | |
export default function useDebounce(value: string, delay: number = 500) { | |
const [debouncedValue, setDebouncedValue] = React.useState(value); | |
React.useEffect(() => { | |
const handler: NodeJS.Timeout = setTimeout(() => { | |
setDebouncedValue(value); | |
}, delay); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.sr-only { | |
border: 0; | |
clip: rect(0, 0, 0, 0); | |
height: 1px; | |
margin: -1px; | |
overflow: hidden; | |
padding: 0; | |
position: absolute; | |
white-space: nowrap; | |
width: 1px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Task 1: Without peeking, write your own recursive factorial method | |
// Task 2: Use your memo function from the previous exercise to memoize your factorial method | |
const memoize = cb => { | |
const cache = {}; | |
return (...args) => { | |
let n = args[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Memoization - caching the result of a function (return value) | |
// Factorial (!) - Ex: 5! === 5 * 4 * 3 * 2 * 1 | |
// Task 1: Write a function, times10, that takes an argument, n, and multiples n times 10 | |
// a simple multiplication fn | |
const times10 = n => { | |
return n * 10; | |
}; | |
console.log("~~~~~~~~~~~~~~TASK 1~~~~~~~~~~~~~~"); |
NewerOlder