Usage: npx https://gist.github.com/gnbaron/48d417e54fb9527a24422546b3ef763c src/folder
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
| window.getReduxStores = () => { | |
| const stores = [] | |
| const traverse = (element) => { | |
| const store = | |
| element?.memoizedState?.element?.props?.store || | |
| element?.pendingProps?.store || | |
| element?.stateNode?.store | |
| if (store) { |
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, ReactNode } from "react" | |
| export function useMediaQuery(query: string) { | |
| const [matches, setMatches] = useState(false) | |
| useEffect(() => { | |
| const media = window.matchMedia(query) | |
| if (media.matches !== matches) { | |
| setMatches(media.matches) | |
| } |
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
| /** | |
| * A promise that resolves on next tick. | |
| * Beneficial for waiting for immediately resolved promises without | |
| * lengthy promise chains. | |
| */ | |
| export const flushPromises = (): Promise<void> => | |
| new Promise(resolve => setImmediate(resolve)) |
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 getAttrs() { | |
| const iframe = document.createElement('iframe') | |
| document.body.appendChild(iframe) | |
| return Object.entries(window) | |
| .filter(([k]) => !(k in iframe.contentWindow)) | |
| .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {}) | |
| } |
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
| export function numberWithCommas(x) { | |
| return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | |
| } |
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
| /* Box sizing rules */ | |
| *, | |
| *::before, | |
| *::after { | |
| box-sizing: border-box; | |
| } | |
| /* Remove default padding */ | |
| ul[class], | |
| ol[class] { |