Created
October 1, 2017 02:45
-
-
Save feus4177/199ecda702c85cb6134874c1971b5cfc to your computer and use it in GitHub Desktop.
Basic example using QueryRenderer from RelayJS.
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
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
import {graphql, QueryRenderer} from 'react-relay'; | |
import environment from '@/environment'; | |
import PageBar from '@/components/PageBar'; | |
import Loading from '@/components/Loading'; | |
const manageOrdersQuery = graphql` | |
query ManageOrdersRelay { | |
orders(first: 10){ | |
edges { | |
node { | |
id | |
creationTime | |
dueDate | |
poNumber | |
status | |
lineItems { | |
edges { | |
node { | |
shortDescription | |
quantity | |
unitPrice | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
`; | |
const ManageOrders = ({routes}) => ( | |
<div className="page-content"> | |
<PageBar routes={routes} /> | |
<h1 className="page-title">Manage Orders</h1> | |
<QueryRenderer | |
environment={environment} | |
query={manageOrdersQuery} | |
render={({error, props}) => { | |
if (error) { | |
return <div><h1>Error!</h1><br />{error}</div>; | |
} | |
if (props) { | |
return ( | |
<div> | |
<ul> | |
{props.orders.map((order) => ( | |
<li>{order.id}</li> | |
))} | |
</ul> | |
</div> | |
); | |
} | |
return <div><Loading /></div>; | |
}} | |
/> | |
</div> | |
); | |
ManageOrders.propTypes = { | |
routes: PageBar.propTypes.routes, | |
}; | |
export default ManageOrders; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment