Skip to content
← Public packages

@kentcdodds/package-app-kit

Design tokens, PWA install/update, About/version, cache helpers, and optional realtime notes sync for Kody package apps.

FollowFork

starter-tanstack/app/router-context.ts

31 lines · 850 B · TypeScript
import { createContext, useContext } from 'react'
import type { Note } from './data/notes.ts'

export type AppShellContext = {
	appBasePath: string
	assetBasePath: string
	clientModuleUrl: string | null
	runningSha: string
	/** Server-only: list notes from packageStorage. Undefined in the browser. */
	listNotes?: () => Promise<Array<Note>>
	/** Server-only: format about page data. */
	loadAbout?: () => Promise<{
		sha: string
		shortSha: string
		message: string
		publishedAt: string
		committedAt: string
		codeUrl: string | null
		runningSha: string
	}>
}

export const AppShellReactContext = createContext<AppShellContext | null>(null)

export function useAppShell(): AppShellContext {
	const value = useContext(AppShellReactContext)
	if (!value) {
		throw new Error('useAppShell must be used within AppShellReactContext')
	}
	return value
}