Skip to content

Instantly share code, notes, and snippets.

@kmjones1979
Created November 7, 2023 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmjones1979/0eaa3751a240c390d8d585d467aa8e44 to your computer and use it in GitHub Desktop.
Save kmjones1979/0eaa3751a240c390d8d585d467aa8e44 to your computer and use it in GitHub Desktop.
Example index.ts with table format for Unchain readme
import type { NextPage } from "next";
import { MetaHeader } from "~~/components/MetaHeader";
import { gql } from "@apollo/client";
import { useQuery } from "@apollo/client";
import { Address } from "~~/components/scaffold-eth";
export const GET_MESSAGES = gql`
{
sendMessages(first: 5) {
id
_from
_to
message
}
}
`;
const Home: NextPage = () => {
const { loading, error, data: messagesData } = useQuery(GET_MESSAGES);
const messages = messagesData?.sendMessages || [];
return (
<>
<MetaHeader />
<h1>Messages</h1>
<table className="min-w-[70%]">
<thead>
<tr>
<th>From</th>
<th>To</th>
<th>Message</th>
</tr>
</thead>
<tbody>
{messages.map((message) => (
<tr key={message.id}>
<td><Address address={message._from}/></td>
<td><Address address={message._to}/></td>
<td>{message.message}</td>
</tr>
))}
</tbody>
</table>
</>
);
};
export default Home;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment