Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Last active December 17, 2020 10:17
Show Gist options
  • Save velotiotech/32bbaeb94a65912668bfd0a20deef083 to your computer and use it in GitHub Desktop.
Save velotiotech/32bbaeb94a65912668bfd0a20deef083 to your computer and use it in GitHub Desktop.
import * as React from "react";
import { GetBlogPost } from "./__generated__/GetBlogPost.graphql";
import { useLazyLoadQuery } from "react-relay/hooks";
import { BlogPostHead } from "./BlogPostHead";
import { BlogPostBody } from "./BlogPostBody";
import { graphql } from "react-relay";
interface BlogPostProps {
postId: string;
}
export const BlogPost = ({ postId }: BlogPostProps) => {
const { blogPostById } = useLazyLoadQuery<GetBlogPost>(
graphql`
query GetBlogPost($postId: ID!) {
blogPostById(id: $postId) {
...BlogPostHead_blogPost
...BlogPostBody_blogPost
}
}
`,
{
variables: { postId }
}
);
if (!blogPostById) {
return null;
}
return (
<div>
<BlogPostHead blogPost={blogPostById} />
<BlogPostBody blogPost={blogPostById} />
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment