Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/example-habit-log

A small habit log app built from the app starter: indigo theme, mobile layout, sign-in, and saved entries.

FollowFork

Files

router-context.ts

26 lines · 702 B · TypeScript
import type { QueryClient } from '@tanstack/react-query'
import type { Visitor } from './auth.ts'
import type { Item } from './data/items.ts'

/** Server and browser each provide this; routes never care which one runs. */
export type AppApi = {
	listItems: () => Promise<Array<Item>>
	addItem: (text: string) => Promise<Item>
	deleteItem: (id: string) => Promise<void>
}

export type RouterContext = {
	queryClient: QueryClient
	api: AppApi
	visitor: Visitor | null
	appBasePath: string
	assetBasePath: string
	clientModuleUrl: string | null
	hostedUrl: string | null
	dehydratedState?: unknown
}

export const itemsQuery = (api: AppApi) => ({
	queryKey: ['items'],
	queryFn: () => api.listItems(),
})