Browse Source

Remember whether downloads are supported

main
Dan Abramov 3 years ago
parent
commit
6c855f7f98
  1. 8
      beta/src/components/MDX/Sandpack/DownloadButton.tsx

8
beta/src/components/MDX/Sandpack/DownloadButton.tsx

@ -7,18 +7,22 @@ import {useSandpack} from '@codesandbox/sandpack-react';
import {IconArrowSmall} from '../../Icon/IconArrowSmall'; import {IconArrowSmall} from '../../Icon/IconArrowSmall';
export interface DownloadButtonProps {} export interface DownloadButtonProps {}
let initialIsSupported = false;
export const DownloadButton: React.FC<DownloadButtonProps> = () => { export const DownloadButton: React.FC<DownloadButtonProps> = () => {
const {sandpack} = useSandpack(); const {sandpack} = useSandpack();
const [supported, setSupported] = React.useState(false); const [supported, setSupported] = React.useState(initialIsSupported);
React.useEffect(() => { React.useEffect(() => {
// This detection will work in Chrome 97+ // This detection will work in Chrome 97+
if ( if (
!supported &&
(HTMLScriptElement as any).supports && (HTMLScriptElement as any).supports &&
(HTMLScriptElement as any).supports('importmap') (HTMLScriptElement as any).supports('importmap')
) { ) {
setSupported(true); setSupported(true);
initialIsSupported = true;
} }
}, []); }, [supported]);
if (!supported) { if (!supported) {
return null; return null;

Loading…
Cancel
Save