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 codeBlocker = () => { | |
return Promise.resolve().then(v => { | |
let i = 0; | |
while(i < 1000000000){ | |
i++; | |
} |
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 codeBlocker = () => { | |
return Promise.resolve().then(() => { | |
let i = 0; | |
while(i < 1000000000){ | |
i++; | |
} | |
return "Loop is Completed"; |
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 codeBlocker = () => { | |
return new Promise((resolve, reject) => { | |
let i = 0; | |
while(i < 1000000000){ | |
i++; | |
} | |
resolve("Loop is Completed"); |
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 codeBlocker = () => { | |
let i = 0; | |
while(i < 1000000000){ | |
i++; | |
} | |
return "Loop is Completed"; | |
} |
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 fetch from "node-fetch"; | |
const promise = fetch("https://jsonplaceholder.typicode.com/todos/1"); | |
promise | |
.then(res => res.json()) | |
.then(user => { | |
throw new Error("An error has occured"); | |
return user; | |
}) |
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 fetch from "node-fetch"; | |
const promise = fetch("https://jsonplaceholder.typicode.com/todos/1"); | |
promise | |
.then(res => res.json()) | |
.then(user => console.log("user title: ", user.title)) | |
console.log("Synchronous") |
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
console.log("Sycnhronous 1"); | |
setTimeout(()=> console.log("Timeout 2"), 0); | |
Promise.resolve().then(()=> console.log("Promise 3")); | |
console.log("Synchronous 4") | |
// OUTPUT | |
// Sycnhronous 1 |
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 React, { useState } from "react"; | |
const MyComponent = () => { | |
const [fullname, setFullname] = useState({ firstname: "", lastname: "" }); | |
const onClickHandler = () => { | |
console.log(fullname); | |
}; | |
return ( |
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 React, { useState, useEffect, useRef } from "react"; | |
function App() { | |
const [data, setData] = useState([]); | |
const [enteredFilter, setEnteredFilter] = useState(""); | |
const inputRef = useRef(); | |
const fetchData = async () => { | |
let response = await fetch("https://jsonplaceholder.typicode.com/users/"); | |
let responseData = await response.json(); |
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 React, { useState, useEffect, useRef } from "react"; // first, we import useRef from react | |
function App() { | |
const [data, setData] = useState([]); | |
const [enteredFilter, setEnteredFilter] = useState(""); | |
const inputRef = useRef(); // second, we initialize a variable by useRef | |
const fetchData = async () => { | |
let response = await fetch("https://jsonplaceholder.typicode.com/users/"); | |
let responseData = await response.json(); |