Skip to content

Instantly share code, notes, and snippets.

@undrafted
undrafted / env-var-in-script.sh
Created March 11, 2020 14:02
Use env variables in package.json
"scripts": {
"e2e:staging": "yarn run $(grep API_KEY .env | cut -d '=' -f2)",
},
const preloadLazy = (dynamicImport) => {
let promise;
function load() {
if(!promise) {
promise = dynamicImport();
}
return promise;
}
const component = React.lazy(load);
export const preloadImage = (url: string) => {
return new Promise(resolve => {
const img = document.createElement('img');
img.src = url;
img.onload = () => resolve(src);
});
};
import React, { PureComponent, ReactNode } from 'react';
const isBrowser = () => typeof window !== 'undefined' && typeof document !== 'undefined';
const shouldPolyfillIntersectionObserver = () =>
isBrowser() &&
!(
'IntersectionObserver' in window &&
'IntersectionObserverEntry' in window &&
'intersectionRatio' in IntersectionObserverEntry.prototype
const svg = document.querySelector("svg");
const bbox = svg.getBBox();
svg.setAttribute("viewBox", [bbox.x, bbox.y, bbox.width, bbox.height].join(" "));
console.log(svg.outerHTML);