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 SomeEnum = { | |
SomeValue: 'SomeValue', | |
SomeOtherValue: 'SomeOtherValue' | |
} as const; | |
type SomeEnumKey = keyof typeof SomeEnum |
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
type FooContextType = { some: 'type' }; | |
export const FooContext = React.createContext<FooContextType | undefined>( | |
undefined | |
); | |
export function FooProvider(props: { children: React.ReactNode }): JSX.Element { | |
const value = useFoo(); | |
return ( | |
<FooContext.Provider value={value}>{props.children}</FooContext.Provider> |
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
declare global { | |
interface Window { | |
someSDK: SomeSDKType | undefined; | |
} | |
} | |
/** | |
* Wrap a script-added SDK so it is usable in server and client contexts. | |
* This allows it to be freely used without errors related to undefined `window` | |
*/ |
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
/** | |
* Safely execute browser only code. | |
* | |
* @param fn - The function to execute. | |
* @param fallback - Optional default return value. | |
* | |
*/ | |
function browserOnly<T>( | |
fn: (window: Window, document: Document) => T, | |
fallback?: T |
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. Add or subtract the percentage given in the problem from 100% to determine what percentage we have. | |
2. Find 1% by dividing by the percentage found in the previous step. | |
3. Find 100% (original amount) by multiplying your answer in step 2 by 100. | |
<100% Example: | |
A shop is having a sale where all items are 30% off. | |
An item is on sale for $84. | |
What was the original price of the item? | |
100% - 30% = 70% of the original price |
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 sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); |
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 useGoBackBrowserSync() { | |
useEffect(() => { | |
return history.listen((newLocation, action) => { | |
if (action === 'POP') { | |
history.goBack(); | |
} | |
}); | |
}, [history]); | |
} |
NewerOlder