Skip to content

Instantly share code, notes, and snippets.

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