Skip to content

Commit

Permalink
✨ infer loader type
Browse files Browse the repository at this point in the history
  • Loading branch information
Girish21 committed Dec 10, 2022
1 parent c30711a commit 1a5dd91
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/remix-app/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
DataFunctionArgs,
LinksFunction,
LoaderFunction,
MetaFunction,
} from '@remix-run/cloudflare'
import { json } from '@remix-run/cloudflare'
Expand All @@ -24,17 +24,17 @@ export let meta: MetaFunction = () => ({

export let links: LinksFunction = () => [{ rel: 'stylesheet', href: styles }]

export let loader: LoaderFunction = async ({ context }) => {
export let loader = async ({ context }: DataFunctionArgs) => {
let id = context.env.COUNTER.idFromName('root')
let object = context.env.COUNTER.get(id)
let doResponse = await object.fetch('https://../increment')
let count = Number(await doResponse.text())

return json<LoaderData>({ count })
return json({ count })
}

export default function App() {
let loaderData = useLoaderData<LoaderData>()
let loaderData = useLoaderData<typeof loader>()

return (
<html lang='en'>
Expand All @@ -52,7 +52,3 @@ export default function App() {
</html>
)
}

type LoaderData = {
count: number
}

0 comments on commit 1a5dd91

Please sign in to comment.