Last active
July 19, 2018 11:31
-
-
Save jermsam/365c45718ce8a220d821981b68543b48 to your computer and use it in GitHub Desktop.
A Grid to be used to display Products that are fetched from the remote end by sending a find request
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
// src/DisplayGrid.js | |
import React,{Component} from 'react' | |
import { Container,Divider,Header,Card,Button } from 'semantic-ui-react'; | |
import {Link} from 'react-router-dom' | |
import client from './feathers' | |
export default class DisplayGrid extends Component { | |
state = { | |
products:[] | |
}; | |
componentDidMount(){ | |
this.fetchFromRemote() | |
} | |
fetchFromRemote =()=>client.service('products').find({ | |
query: { | |
$sort: { | |
price: -1 // sort them by price descending | |
} | |
} | |
}).then( | |
res=>this.setState({products:res.data}) | |
) | |
render() { | |
const { products } = this.state; | |
return ( | |
<Container textAlign='center'> | |
<Divider section hidden/> | |
<Header> Display Grid</Header> | |
<Button as={Link} to='/create'>Add New Product </Button> | |
<Divider hidden/> | |
<Card.Group> | |
{products.map( | |
({id,name,description,price})=> <Card key={id}> | |
<Card.Content> | |
<Card.Header> | |
{name} | |
</Card.Header> | |
<Card.Description> | |
{description} | |
</Card.Description> | |
<Card.Meta> | |
{price} | |
</Card.Meta> | |
</Card.Content> | |
</Card> | |
)} | |
</Card.Group> | |
</Container> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment