Skip to content

Commit

Permalink
Added Rendered Props Query
Browse files Browse the repository at this point in the history
  • Loading branch information
myhendry committed May 6, 2018
1 parent 1c82184 commit e69298f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
11 changes: 4 additions & 7 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import React, { Component } from "react";
import { compose, graphql } from "react-apollo";

import { GET_TWEETS } from "./graphql/queries";
import Board from "./components/Board";
import logo from "./logo.svg";
import "./App.css";

class App extends Component {
render() {
console.log(this.props);
const { loading, data: { getTweets } } = this.props;
console.log(getTweets);
return (
<div className="App">
<header className="App-header">
Expand All @@ -24,15 +20,16 @@ class App extends Component {
Read about this{" "}
<a href="https://github.com/apollographql/ticketmaster-rest-api-wrapper">
server on GitHub
</a>.
</a>
</p>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<Board />
</div>
);
}
}

export default compose(graphql(GET_TWEETS))(App);
export default App;
30 changes: 30 additions & 0 deletions client/src/components/Board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { Component } from "react";
import { Query } from "react-apollo";

import { GET_TWEETS } from "../graphql/queries";

class Board extends Component {
render() {
return (
<Query query={GET_TWEETS}>
{({ loading, error, data: { getTweets } }) => {
if (loading) {
return <h3>Loading...</h3>;
}
if (error) {
return <h3>Oh No!!!</h3>;
}
return getTweets.map(t => (
<div>
<h2>{t.text}</h2>
<h3>{t._id}</h3>
<h3>{t.createdAt}</h3>
</div>
));
}}
</Query>
);
}
}

export default Board;

0 comments on commit e69298f

Please sign in to comment.