Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
chore: update next (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradens authored Oct 27, 2023
1 parent 544474f commit fc105b1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 39 deletions.
Binary file modified examples/next/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@types/node": "20.5.7",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"next": "13.4.19",
"next": "14",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.2.2",
Expand Down
40 changes: 17 additions & 23 deletions examples/next/src/app/GetNetworks.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
"use client"
import { Defined } from "@definedfi/sdk/dist/sdk";
import { Network } from "@definedfi/sdk/src/resources/graphql";

import { Defined } from '@definedfi/sdk/dist/sdk'
import { useEffect, useState } from 'react'
import { Network } from '@definedfi/sdk/src/resources/graphql'
async function getData() {
const sdk = new Defined(process.env.NEXT_PUBLIC_DEFINED_API_KEY || "");
const res = await sdk.send<{ getNetworks: Network[] }>(
`query { getNetworks { id, name } }`,
);
if (!res.getNetworks) {
// This will activate the closest `error.js` Error Boundary
throw new Error("Failed to fetch data");
}
return res.getNetworks;
}

// Don't do this -- instead use a .env file and next server routes
const sdk = new Defined(process.env.NEXT_PUBLIC_DEFINED_API_KEY || '')

export default function GetNetworks() {
const [networks, setNetworks] = useState<Network[]>([])
useEffect(() => {
const getNetworks = async () => {
const res = await sdk.send<{getNetworks: Network[]}>(`query { getNetworks { id, name } }`)
setNetworks(res.getNetworks)
}
getNetworks()
}, [])

return (
<pre>
{JSON.stringify(networks, null, 2)}
</pre>
)
}
export default async function GetNetworks() {
const data = await getData();
return <pre>{JSON.stringify(data, null, 2)}</pre>;
}
19 changes: 10 additions & 9 deletions examples/next/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import './globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import "./globals.css";

const inter = Inter({ subsets: ['latin'] })
import type { Metadata } from "next";
import { Inter } from "next/font/google";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: {
children: React.ReactNode
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
)
);
}
12 changes: 6 additions & 6 deletions examples/next/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Image from 'next/image'
import styles from './page.module.css'
import GetNetworks from './GetNetworks'
import Image from "next/image";

export default function Home() {
import GetNetworks from "./GetNetworks";
import styles from "./page.module.css";

export default function Home() {
return (
<main className={styles.main}>
<div className={styles.description}>
Expand All @@ -17,7 +17,7 @@ export default function Home() {
target="_blank"
rel="noopener noreferrer"
>
By{' '}
By{" "}
<Image
src="/vercel.svg"
alt="Vercel Logo"
Expand Down Expand Up @@ -86,5 +86,5 @@ export default function Home() {
</a>
</div>
</main>
)
);
}

0 comments on commit fc105b1

Please sign in to comment.