This file contains hidden or 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
function useThrottle(value, interval = 500) { | |
const [throttledValue, setThrottledValue] = useState(value); | |
const lastExecuted = useRef(Date.now()); | |
useEffect(() => { | |
if (Date.now() >= lastExecuted.current + interval) { | |
lastExecuted.current = Date.now(); | |
setThrottledValue(value); | |
} | |
else { | |
const timerId = setTimeout(() => { |
This file contains hidden or 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
function useLocalStorageState( | |
key, | |
defaultValue = '', | |
// the = {} fixes the error we would get from destructuring when no argument was passed | |
// Check https://jacobparis.com/blog/destructure-arguments for a detailed explanation | |
{serialize = JSON.stringify, deserialize = JSON.parse} = {}, | |
) { | |
const [state, setState] = React.useState(() => { | |
const valueInLocalStorage = window.localStorage.getItem(key) | |
if (valueInLocalStorage) { |
This file contains hidden or 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
const delay = (delay, value) => { | |
let timeout; | |
let _reject = null; | |
const promise = new Promise((resolve, reject) => { | |
_reject= reject; | |
timeout = setTimeout(resolve, delay, value); | |
}); | |
return { | |
promise, | |
cancel() { |
This file contains hidden or 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
// 1. Go to https://analytics.twitter.com/ | |
// 2. Keep scrolling till the end until all the stats data is loaded | |
// 3. Right click on page click on last option "Inspect" a window should open select console from that | |
// 4. copy this entire function | |
function dataMiner(){ | |
let masterArray = []; |
This file contains hidden or 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
const begin = performance.now(); | |
// include the operation you want to measure: | |
for let(i = 0; i < 100; i++) { | |
console.log(i); | |
} | |
const end = performance.now(); | |
const timeElapsed = end - begin; |
This file contains hidden or 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
function checkFonts() { | |
document.fonts.onloadingdone = function (fontFaceSetEvent) { | |
console.log( | |
"🚀 ~ file: default.js ~ line 27 ~ checkFonts ~ fontFaceSetEvent", | |
fontFaceSetEvent | |
); | |
alert( | |
"onloadingdone we have " + | |
fontFaceSetEvent.fontfaces.length + | |
" font faces loaded" |
This file contains hidden or 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 { useTheme, useColorMode } from "@chakra-ui/react"; | |
export function useColor() { | |
const theme = useTheme(); | |
const { colorMode } = useColorMode(); | |
const { mode } = theme.colors; | |
return { | |
mode: colorMode, | |
color: (colorName) => mode[colorMode][colorName], | |
}; |
This file contains hidden or 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
/** | |
* A simple method of demonstrating how you can use the Next.js | |
* internal API for 'server-less' functions. We export an async function. | |
* | |
* We import the nodemailer package to handle SMTP transactional mail. | |
* | |
* In a production environment, you could create a .env.production | |
* to hold your secure details, e.g., | |
* HOST, AUTH_USER, AUTH_PASS | |
* |
This file contains hidden or 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
// pages/api/my-api-call.js | |
const fetch = require("node-fetch"); | |
export default async (req, res) => { | |
try { | |
const apiCall = await fetch(`http://api-path?api-key=${process.env.SECRET_KEY}`); | |
if (apiCall.response.status === 200) { | |
res.status(200).json({}); | |
res.end(); | |
return res; |
This file contains hidden or 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
j// [page].js | |
import { Box, Flex, Image } from "@chakra-ui/react"; | |
import { Section } from "@/components/section"; | |
import { getPage, getRecords } from "@/libs/airtable"; | |
const Sandbox = ({ page }) => { | |
console.log("🚀 ~ file: sandbox.js ~ line 6 ~ Sandbox ~ page", page); | |
return ( | |
<> |