Last active
November 7, 2019 21:41
-
-
Save john-osullivan/1c8b50dc6c761435b6a9f50dccf76a10 to your computer and use it in GitHub Desktop.
Dev Diaries #3 - Refresh w/ Hook
This file contains 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 function App<Additional extends AdditionalArgs>(props: AppProps<Additional>): ReactElement { | |
const { args, renderFunc } = props; | |
const [authData, setAuthData] = useState(JSON.parse(args.authFile as string)); | |
const API = new DappbotAPI({ | |
authData, | |
setAuthData: (auth) => { | |
setAuthData(auth); | |
saveAuthToFile(auth); | |
}, | |
dappbotUrl: args.apiUrl | |
}) | |
useEffect(function refreshIfStale() { | |
if (API.hasStaleAuth()) { | |
API.refreshAuth() | |
} | |
}, [API, authData]) | |
return API.hasStaleAuth() ? ( | |
<Loader message='Refreshing your authData...' /> | |
) : ( | |
renderFunc({ | |
API, authData, setAuthData, args | |
}) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment