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 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 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 isSafari = () => navigator.vendor.match(/apple/i) && | |
| !navigator.userAgent.match(/crios/i) && | |
| !navigator.userAgent.match(/fxios/i) && | |
| !navigator.userAgent.match(/Opera|OPT\//); |
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 } from 'react' | |
| const Button = () => { | |
| const [ LazyComponent, setLazyComponent ] = useState(null) | |
| const loadLazyComponent = async () => { | |
| if (LazyComponent !== null) { | |
| return | |
| } |
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 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 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
| {typeof window !== 'undefined' && ( | |
| <React.Suspense fallback={<Loading />}> | |
| <LazyThing /> | |
| </React.Suspense> | |
| )} |
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 dynamic from 'next/dynamic' | |
| const NavMenu = dynamic( | |
| () => import('./NavMenu'), | |
| { loading: () => <p>Loading...</p> } | |
| ) | |
| function Header() { | |
| const [showMenu, setShowMenu] = useState(false) | |
| return ( |
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 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 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(/* webpackChunkName: "NavMenu" */ './NavMenu') |
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(/* webpackChunkName: "<Component Name>" */ '<path>/<to>/<component>') |
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 } from 'react' | |
| const NavMenu = React.lazy(() => import('./NavMenu')) | |
| function Header() { | |
| const [showMenu, setShowMenu] = useState(false) | |
| return ( | |
| <div> | |
| <React.Suspense fallback={<p>Loading...</p>}> | |
| {showMenu && <NavMenu />} |