Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

shared-function.tsx

17 lines458 Bytes

1import { createFileRoute } from '@tanstack/react-router'
2​
3const cache = new Map()
4function getCached(key: string) {
5 return cache.get(key)
6}
7function setCached(key: string, val: unknown) {
8 cache.set(key, val)
9}
10​
11export const Route = createFileRoute('/cached')({
12 loader: async () => {
13 setCached('data', await fetch('/api').then((r) => r.json()))
14 return getCached('data')
15 },
16 component: () => <div>{JSON.stringify(getCached('data'))}</div>,
17})