Skip to content

Instantly share code, notes, and snippets.

@jermsam
Last active July 19, 2018 11:30
Show Gist options
  • Save jermsam/7592ac671fdd557a97ddbadee5235693 to your computer and use it in GitHub Desktop.
Save jermsam/7592ac671fdd557a97ddbadee5235693 to your computer and use it in GitHub Desktop.
Editing DisplayGrid to get notified when product is 'emitted' events are emited by remote end
// 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()
client.service('products').on('created',()=>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