utils.ts
1 function fetchUser(id: string) {
2- const res = await fetch(`/api/user/${id}`)
3- return res.json()
4 }
5
6-export const cache = new Map()
7
8 // TODO: handle errors
9 export default { fetchUser }
1 async function fetchUser(id: string) {
2+ if (cache.has(id)) return cache.get(id)
3+ const res = await fetch(`/api/user/${id}`)
4 }
5
6+const cache = new Map<string, unknown>()
7
8 // cache hit avoids redundant fetches
9 export default { fetchUser, cache }