Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit e0b2cdc

Browse files
committed
fix: fix useDeno hook (#127)
1 parent e83ade4 commit e0b2cdc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

framework/react/hooks.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export function withRouter<P>(Component: ComponentType<P>) {
4444
*
4545
* ```tsx
4646
* export default function App() {
47-
* const version = useDeno(() => Deno.version)
48-
* return <p>{version.deno}</p>
47+
* const version = useDeno(() => Deno.version.deno)
48+
* return <p>{version}</p>
4949
* }
5050
* ```
5151
*
@@ -56,7 +56,7 @@ export function useDeno<T = any>(callback: () => (T | Promise<T>), revalidate?:
5656
const id = arguments[2] // generated by compiler
5757
const { pathname } = useRouter()
5858
return useMemo(() => {
59-
const global = window as any
59+
const global = globalThis as any
6060
const dataUrl = 'data://' + pathname
6161
const eventName = 'useDeno-' + dataUrl
6262
const key = dataUrl + '#' + id
@@ -83,7 +83,10 @@ export function useDeno<T = any>(callback: () => (T | Promise<T>), revalidate?:
8383
return v
8484
}
8585
}
86-
return global[key].value || null
86+
if (key in global) {
87+
return global[key].value
88+
}
89+
return null
8790
}, [id, pathname])
8891
}
8992

0 commit comments

Comments
 (0)