11import '../styles/index.css' ;
22
3- import React , { FunctionComponent , useState } from 'react' ;
3+ import React , { FunctionComponent , MouseEvent } from 'react' ;
44import { AppProps } from 'next/app' ;
55import Div100vh from 'react-div-100vh' ;
66import NProgress from 'nprogress' ;
7+ import usePortal from 'react-useportal' ;
78import Router from 'next/router' ;
89import Head from 'next/head' ;
910
@@ -19,8 +20,8 @@ Router.events.on('routeChangeComplete', () => NProgress.done());
1920Router . events . on ( 'routeChangeError' , ( ) => NProgress . done ( ) ) ;
2021
2122const App : FunctionComponent < AppProps > = ( { Component, pageProps } ) => {
22- const [ showFallbackShare , setShowFallbackShare ] = useState ( false ) ;
23- function openShareDialog ( ) {
23+ const { openPortal , closePortal , isOpen , Portal } = usePortal ( ) ;
24+ function openShareDialog ( e : MouseEvent < HTMLButtonElement > ) {
2425 // try to open native share dialog
2526 if ( window . navigator . share ) {
2627 const title = document . title ;
@@ -30,23 +31,25 @@ const App: FunctionComponent<AppProps> = ({ Component, pageProps }) => {
3031 return window . navigator . share ( { title, text : `${ text } ${ url } ` } ) ;
3132 }
3233 // fallback to custom native share dialog
33- return setShowFallbackShare ( true ) ;
34+ return openPortal ( e ) ;
3435 }
35- function closeShareDialog ( ) {
36- setShowFallbackShare ( false ) ;
36+ function closeShareDialog ( e : MouseEvent < HTMLButtonElement > ) {
37+ closePortal ( e ) ;
3738 }
3839 return (
3940 < >
4041 < Head >
4142 { /* Import CSS for nprogress */ }
4243 < link rel = "stylesheet" type = "text/css" href = "/nprogress.css" />
4344 </ Head >
44- < ShareContext . Provider value = { { openShareDialog, closeShareDialog, isOpen : showFallbackShare } } >
45- < Div100vh className = "relative" >
45+ < ShareContext . Provider value = { { openShareDialog, closeShareDialog, isOpen : isOpen } } >
46+ < Div100vh >
4647 < Component { ...pageProps } />
47- < FallbackShare />
4848 < MobileMenu />
4949 </ Div100vh >
50+ < Portal >
51+ < FallbackShare />
52+ </ Portal >
5053 </ ShareContext . Provider >
5154 </ >
5255 ) ;
0 commit comments