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 from 'react' | |
import Router from 'next/router' | |
const HistoryContext = React.createContext([]); | |
export class HistoryProvider extends React.Component { | |
state = { | |
history: [] | |
} |
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
/** | |
* Convert an imageURL to a | |
* base64 dataURL via canvas | |
* | |
* @param {String} url | |
* @param {Object} options | |
* @param {String} options.outputFormat [outputFormat='image/png'] | |
* @param {Float} options.quality [quality=1.0] | |
* @return {Promise} | |
* @docs https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement#Methods |
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 from 'react' | |
class App extends Component { | |
componentDidMount() { | |
// Subscribe here | |
} | |
componentWillUnmount() { | |
// Unsubscribe here | |
} |
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 { useEffect } from 'react' | |
function useClickOutside(ref, onClickOutside) { | |
useEffect(() => { | |
const handleClick = (event) => { | |
if (!ref.current || !ref.current.contains(event.target)) { | |
onClickOutside(event) | |
} | |
} | |
window.addEventListener('click', handleClick) |
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 { useContext } from 'react' | |
import { __RouterContext as RouterContext, matchPath } from 'react-router-dom' | |
export default function useRouter (options = {}) { | |
const context = useContext(RouterContext) | |
const location = options.location || context.location | |
const match = options.path | |
? matchPath(location.pathname, options) | |
: context.match |
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 { useRef, useEffect } from 'react' | |
/** | |
* This hook reduces the amount of rebindings. | |
* Use it when your props change a lot. | |
* | |
* @param {DomRef} targetRef The reference to the dom node | |
* @param {String} eventName The eventName you want to bind | |
* @param {Function} handler The actual event handler | |
*/ |
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 from 'react' | |
import ReactDOM from 'react-dom' | |
const isServer = typeof window === 'undefined' | |
const Context = React.createContext([]) | |
export const HeadProvider = ({ head, children }) => ( | |
<Context.Provider value={head}> | |
{children} | |
</Context.Provider> |
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
self.addEventListener('activate', function(event) { | |
event.waitUntil( | |
caches.keys().then(function(cacheNames) { | |
return Promise.all( | |
cacheNames.filter(function(cacheName) { | |
// Return true if you want to remove this cache, | |
// but remember that caches are shared across | |
// the whole origin | |
return true | |
}).map(function(cacheName) { |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<button id='audioMutedTrue'>audioMuted true</button> | |
<button id='setAudioMutedTrue'>setAudioMuted true</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 { useState, useEffect, RefObject } from "react"; | |
import ResizeObserver from "resize-observer-polyfill"; | |
const useElementResize = (ref: RefObject<HTMLElement>) => { | |
const [rect, setRect] = useState({}); | |
useEffect(() => { | |
if (!ref.current) return | |
const ro = new ResizeObserver((entries, observer) => { | |
for (const entry of entries) { |