Last active
April 12, 2022 06:41
-
-
Save ApolloTang/adb8571f97923fc6575ae24387c3bae2 to your computer and use it in GitHub Desktop.
Revisions
-
ApolloTang revised this gist
Apr 12, 2022 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,12 +17,12 @@ const ClientSessionProvide = (props: propsType) => { useEffect(() => { resetClientSession = () => { if (id) { clearTimeout(id); } ctx.isFullLogin = true; id = setTimeout(() => { ctx.isFullLogin = false; }, fifteenMin ); }; }, []); -
ApolloTang revised this gist
Apr 12, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -43,10 +43,10 @@ export { function Foo(props: propsType) { const { children } = props; const { isFullLogin } = React.useContext(SessionCtx); return ( <> <div>{ isFullLogin }</div> {children} </> ); -
ApolloTang revised this gist
Apr 12, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -43,10 +43,10 @@ export { function Foo(props: propsType) { const { children } = props; const {ctx } = React.useContext(SessionCtx); return ( <> <div>{ctx.isFullLogin}</div> {children} </> ); -
ApolloTang revised this gist
Apr 12, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export { ClientSessionProvide, resetClientSession, // <--- This is a live export see // https://stackoverflow.com/questions/32558514/javascript-es6-export-const-vs-export-let // it is assign the value after ClientSessionProvide has mounted. }; function Foo(props: propsType) { -
ApolloTang created this gist
Apr 12, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ import React, { useEffect } from 'react'; let resetClientSession: () => void; const SessionCtx = React.createContext(null); type propsType = { children: JSX.Element; }; const ClientSessionProvide = (props: propsType) => { const { children } = props; let id; const ctx = { isFullLogin: false }; // I am not sure if this should be a useState useEffect(() => { resetClientSession = () => { if (id) { clearInterval(id); } ctx.isFullLogin = true; id = setInterval(() => { ctx.isFullLogin = false; }, 1000); }; }, []); return ( <SessionCtx.Provider value={ctx}> <Foo>{children}</Foo> </SessionCtx.Provider> ); }; export { SessionCtx, ClientSessionProvide, resetClientSession, // <--- This is a live export see // https://stackoverflow.com/questions/32558514/javascript-es6-export-const-vs-export-let }; function Foo(props: propsType) { const { children } = props; const { isFullLogin } = React.useContext(SessionCtx); return ( <> <div>{isFullLogin}</div> {children} </> ); }