Skip to content

Instantly share code, notes, and snippets.

@john-osullivan
Last active November 7, 2019 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john-osullivan/1c8b50dc6c761435b6a9f50dccf76a10 to your computer and use it in GitHub Desktop.
Save john-osullivan/1c8b50dc6c761435b6a9f50dccf76a10 to your computer and use it in GitHub Desktop.
Dev Diaries #3 - Refresh w/ Hook
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