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

Loading…
Cancel
Save