Skip to content

Instantly share code, notes, and snippets.

@bicknest
Created May 15, 2020 21:33
Show Gist options
  • Save bicknest/9f7864abe0e8e1c059fd9f5242a01b6b to your computer and use it in GitHub Desktop.
Save bicknest/9f7864abe0e8e1c059fd9f5242a01b6b to your computer and use it in GitHub Desktop.
Forms Parent early on
import React from "react";
import { useParams } from "react-router-dom";
import { gql, useQuery } from "@apollo/client";
import Container from "@material-ui/core/Container";
import Typography from "@material-ui/core/Typography";
import ProfileForm from "./ProfileForm";
const ProfileFormsQuery = gql`
query ProfileForms {
profile(pk: $pk) {
...ProfileForm
}
}
${ProfileForm.fragments.data}
`;
export default function Forms() {
const { pk } = useParams();
const pk_num = Number(pk);
const { data, loading, error } = useQuery(ProfileFormsQuery, {
variables: {
pk: pk_num
}
});
if (error) {
return (
<Container>
<Typography>OH NO! ERROR! {error.message}</Typography>
</Container>
);
}
if (loading || !data) {
return (
<Container>
<Typography>LOADING</Typography>
</Container>
);
}
const profile = data && data.profile;
return (
<Container>
<Typography variant="h1">Profile Forms</Typography>
<ProfileForm profile={profile} />
</Container>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment