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