Skip to content

Instantly share code, notes, and snippets.

import { useEffect, useState, FormEvent } from 'react';
type FormField = {
field: string;
errorMessage?: string;
hasError?: boolean;
required?: boolean;
value?: boolean | string | string[] | null;
};
{
"General": {
"Code": "AAPL",
"Type": "Common Stock",
"Name": "Apple Inc",
"Exchange": "NASDAQ",
"CurrencyCode": "USD",
"CurrencyName": "US Dollar",
"CurrencySymbol": "$",
"CountryName": "USA",
React.useEffect( () => {
const abortCtrl = new AbortController();
fetch(
`some_url`,
{
method: "get",
headers: new Headers( {
"Content-Type": "application/json",
"Accept": "application/json",
@arnonate
arnonate / next-getPostData
Created October 5, 2020 19:30
get post data from .md in Next getStaticProps
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;
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,
// useModal.ts
import React from "react";
export const useModal = () => {
const [modalIsVisible, setModalIsVisible] = React.useState(false);
const toggleModalVisibility = () => setModalIsVisible(!modalIsVisible);
return { modalIsVisible, toggleModalVisibility };
};
// 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);
.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;
// 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];
// 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~~~~~~~~~~~~~~");