Last active
July 7, 2021 08:44
-
-
Save RStankov/0f062b229af2b46312b0129a1800f3d5 to your computer and use it in GitHub Desktop.
This file contains 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 * from 'react'; | |
export function mapNodes(connection, fn) { | |
return connection.edges.map(({ node }) => fn(node)); | |
} | |
export function withLoading(Component) { | |
return (props) => { | |
if (props.data.loading) { | |
return <div>Loading...</div>; | |
} | |
return <Component {...props} />; | |
} | |
} |
This file contains 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 * from react; | |
import LoadMoreButton from 'LoadMoreButton'; | |
import QUERY from './Query.graphql'; | |
import { withLoading, mapNodes } from 'graphql'; | |
import { graphql, compose } from 'react-apollo'; | |
export function Content({ data }) { | |
return ( | |
<div> | |
<h1>Posts</h1> | |
<div> | |
{mapNodes(data.allPosts, post => <PostItem key={post.id} post={post} />)} | |
</div> | |
<LoadMoreButton data={data} path="allPosts" /> | |
</div> | |
); | |
} | |
export default compose( | |
graphql(QUERY), | |
withLoading, | |
)(Content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment