Created
August 22, 2018 18:41
-
-
Save zth/6e8fac2dda7f85f05de80d291167498c to your computer and use it in GitHub Desktop.
Sample App component
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 characters
// @flow | |
import * as React from 'react'; | |
import { QueryRenderer, graphql } from 'react-relay'; | |
import { environment } from '../config/createRelayEnvironment'; | |
import type { AppQueryResponse } from './__generated__/AppQuery.graphql'; | |
const query = graphql` | |
query AppQuery { | |
viewer { | |
id | |
currentUserCount | |
} | |
} | |
`; | |
export class App extends React.Component<{}> { | |
render() { | |
return ( | |
<div className="App"> | |
<QueryRenderer | |
environment={environment} | |
query={query} | |
render={({ | |
error, | |
props | |
}: { | |
error: Error, | |
props: AppQueryResponse | |
}) => { | |
if (error) { | |
console.error(error); | |
return <div className="ErrorScreen">Something went wrong!</div>; | |
} | |
if (props) { | |
return ( | |
<div className="AppDisplayer"> | |
<h1>User count: {props.viewer.currentUserCount}</h1> | |
</div> | |
); | |
} | |
// No error or props means we're loading still | |
return <div className="AppDisplayer--loading">Loading app...</div>; | |
}} | |
/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment