This file contains 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 function () { | |
const a = await asyncFunction(2) | |
const b = await asyncFunction(a) | |
const c = await asyncFunction(b) | |
const d = await asyncFunction(c) | |
console.log(d); | |
})() | |
function asyncFunction(x, fn){ | |
return new Promise(function (resolve, reject) { |
This file contains 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 asyncFunction(x) { | |
return new Promise(function (resolve, reject) { | |
if(typeof x === 'number' && !isNaN(x)){ | |
resolve( x * x) | |
} else { | |
reject(new Error('It\'s not a number')) | |
} | |
}) | |
} |
This file contains 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
/** | |
* Gets keyboard-focusable elements within a specified element | |
* @param {HTMLElement} [element=document] element | |
* @returns {Array} | |
*/ | |
function getKeyboardFocusableElements(element = document) { | |
return [ | |
...element.querySelectorAll( | |
'a[href], button, input, textarea, select, details,[tabindex]:not([tabindex="-1"])' | |
), |
This file contains 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, { useContext } from 'react'; | |
import { AuthContext } from './AuthContext'; | |
const UserProfile = () => { | |
const { user, logout } = useContext(AuthContext); | |
return ( | |
<div> | |
<h2>Welcome, {user ? user.name : 'Guest'}</h2> | |
{user && <button onClick={logout}>Logout</button>} |
This file contains 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 "./App.css"; | |
import React, { useContext } from 'react'; | |
import Switch from "./Switch"; | |
import { ThemeProvider, useTheme } from './ThemeContext'; // Import from ThemeContext.js | |
const Title = ({ children }) => { | |
const { theme } = useTheme(); | |
return ( | |
<h2 | |
style={{ |