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
document.querySelector('.copy-button').addEventListener('click', async () => { | |
const src = document.querySelector('.image-to-copy').src | |
try { | |
const blob = await getImageBlobFromUrl(src) | |
await navigator.clipboard.write([ | |
new ClipboardItem({ | |
[blob.type]: blob | |
}) | |
]) | |
alert('Image copied to clipboard!') |
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 getImageBlobFromUrl(url) { | |
const fetchedImageData = await fetch(url) | |
const blob = await fetchedImageData.blob() | |
return blob | |
} |
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
export async function copyToClipboard (text) { | |
try { | |
// try to use Clipboard API | |
await navigator.clipboard.writeText(text); | |
return true | |
} catch (_) { | |
// Clipboard API is not supported | |
const el = document.createElement('textarea') | |
el.value = text | |
document.body.appendChild(el) |
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
const isSafari = () => navigator.vendor.match(/apple/i) && | |
!navigator.userAgent.match(/crios/i) && | |
!navigator.userAgent.match(/fxios/i) && | |
!navigator.userAgent.match(/Opera|OPT\//); |
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, { useState } from 'react' | |
const Button = () => { | |
const [ LazyComponent, setLazyComponent ] = useState(null) | |
const loadLazyComponent = async () => { | |
if (LazyComponent !== null) { | |
return | |
} |
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
const LoadablePlugin = require('@loadable/webpack-plugin') | |
exports.onCreateWebpackConfig = ({ actions, plugins }) => { | |
actions.setWebpackConfig({ | |
plugins: [new LoadablePlugin()] | |
}) | |
} | |
import loadable from '@loadable/component' | |
export default function Page(props) { | |
const LazyComponent = loadable(() => import(`../components/lazyComponent.js`)) |
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
{typeof window !== 'undefined' && ( | |
<React.Suspense fallback={<Loading />}> | |
<LazyThing /> | |
</React.Suspense> | |
)} |
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 dynamic from 'next/dynamic' | |
const NavMenu = dynamic( | |
() => import('./NavMenu'), | |
{ loading: () => <p>Loading...</p> } | |
) | |
function Header() { | |
const [showMenu, setShowMenu] = useState(false) | |
return ( |
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 { | |
BrowserRouter as Router, | |
Switch | |
} from 'react-router-dom' | |
const HomePage = React.lazy(() => import('./Pages/Home')) | |
const LoginPage = React.lazy(() => import('./Pages/Login')) | |
export default function () { |
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(/* webpackChunkName: "NavMenu" */ './NavMenu') |