Skip to content

Instantly share code, notes, and snippets.

@adamjarling
Last active September 24, 2019 20:36
Show Gist options
  • Save adamjarling/a354755f5597ded173e83b10aaf68301 to your computer and use it in GitHub Desktop.
Save adamjarling/a354755f5597ded173e83b10aaf68301 to your computer and use it in GitHub Desktop.
An example React component which uses React Router's match object to grab a url parameter
import React from "react";
import { withRouter } from "react-router";
import ScreenHeader from "../../components/UI/ScreenHeader";
import Error from "../../components/UI/Error";
import Loading from "../../components/UI/Loading";
import { useQuery } from "@apollo/react-hooks";
import { GET_PROJECT } from "../../components/Project/project.query";
const ScreensProject = ({ match }) => {
const { id } = match.params;
const { loading, error, data } = useQuery(GET_PROJECT, {
variables: { projectId: id }
});
if (loading) return <Loading />;
if (error) return <Error error={error} />;
return (
<div>
{data.project && (
<>
<ScreenHeader
title={data.project.title}
description="The following is a list of all active Ingest Sheets for a project"
/>
...
</>
)}
</div>
);
};
export default withRouter(ScreensProject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment