Skip to content

Instantly share code, notes, and snippets.

// DocTitleWithoutCustomHook.jsx
import React, { useState, useEffect } from "react";
function DocTitleWithoutCustomHook() {
const [count, setCount] = useState(0);
useEffect(() => {
document.title = ` count ${count} `;
}, [count]);
const getIngredient = async(ingredient) => {
const ingredients = {
banana: "Banana",
chocolateMilk: "Chocolate Milk",
peanutButter: "Peanut Butter"
}
await delay(1000) // Hypothetical 1000ms delay
return ingredients[ingredient];
const getIngredient = async(ingredient) => {
const ingredients = {
banana: "Banana",
chocolateMilk: "Chocolate Milk",
peanutButter: "Peanut Butter"
}
return ingredients[ingredient];
}
const tick = Date.now();
const log = v => console.log(`${v} - Elapsed: ${Date.now() - tick} ms`)
const getIngredient = async(ingredient) => {
const ingredients = {
banana: "Banana",
chocolateMilk: "Chocolate Milk",
peanutButter: "Peanut Butter"
}
const tick = Date.now();
const log = v => console.log(`${v} - Elapsed: ${Date.now() - tick} ms`)
const getIngredient = async(ingredient) => {
const ingredients = {
banana: "Banana",
chocolateMilk: "Chocolate Milk",
peanutButter: "Peanut Butter"
}
const tick = Date.now();
const log = v => console.log(`${v} - Elapsed: ${Date.now() - tick} ms`)
const getIngredient = async(ingredient) => {
const ingredients = {
banana: "Banana",
chocolateMilk: "Chocolate Milk",
peanutButter: "Peanut Butter"
}
const getIngredient = async(ingredient) => {
const ingredients = {
banana: "Banana",
chocolateMilk: "Chocolate Milk",
peanutButter: "Peanut Butter"
}
return ingredients[ingredient];
}
const getIngredient = async(ingredient) => {
const ingredients = {
banana: "Banana",
chocolateMilk: "Chocolate Milk",
peanutButter: "Peanut Butter"
}
await delay(1000) // Hypothetical 1000ms delay
return ingredients[ingredient];
// async/await syntax
const makeSmoothie = async() => {
const a = await getIngredient("banana");
const b = await getIngredient("chocolateMilk");
return [a, b]
}
makeSmoothie().then(console.log)
const getIngredient = (ingredient) => {
const ingredients = {
banana: "Banana",
chocolateMilk: "Chocolate Milk",
peanutButter: "Peanut Butter"
}
return Promise.resolve(ingredients[ingredient]);
}