Last active
November 7, 2019 10:05
-
-
Save john-osullivan/f4a8a10f52dcdf9c117cba4a00d95dad to your computer and use it in GitHub Desktop.
Dev Diaries #3 - Top-Level App component w/ renderFunc
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
import DappbotAPI from '@eximchain/dappbot-api-client'; | |
export function function App<Additional extends AdditionalArgs>(props: AppProps<Additional>): ReactElement { | |
// We destructure App's two props; the args from | |
// the command, and the renderFunc. | |
const { args, renderFunc } = props; | |
// We use the authFile argument to initialize the | |
// authData, as it will safely default. | |
const [authData, setAuthData] = useState(JSON.parse(args.authFile as string)); | |
// We configure the API with the authData that is | |
// now stored in state, guaranteeing the object will | |
// refresh if the state updates. | |
const API = new DappbotAPI({ | |
authData, | |
setAuthData, | |
dappbotUrl: args.apiUrl | |
}) | |
return ( | |
// react-request-hook depends on axios, they are loaded | |
// together down in the render. When our API client's | |
// resource methods are called, | |
// | |
// e.g. API.public.viewDapp.resource('my-dapp') | |
// | |
// the underlying request provider is this axios here. | |
<RequestProvider value={axios}> | |
{ | |
// Finally, we call the provided renderFunc, | |
// now with a prepared API object. | |
renderFunc({ | |
API, authData, setAuthData, args | |
}) | |
} | |
</RequestProvider> | |
) | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment