This repository was archived by the owner on Jul 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 1
- import { useContext , useEffect , useState } from 'https://esm.sh/react'
1
+ import React , { useContext , useEffect , useState } from 'https://esm.sh/react'
2
2
import { RouterContext } from './context.ts'
3
3
import { AsyncUseDenoError } from './error.ts'
4
4
import events from './events.ts'
@@ -52,3 +52,27 @@ export function useDeno<T = any>(callback: () => (T | Promise<T>), browser?: boo
52
52
53
53
return data
54
54
}
55
+
56
+ /**
57
+ * `withDeno` allows you to use `useDeno` hook with class component.
58
+ *
59
+ * ```javascript
60
+ * class MyComponent extends React.Component {
61
+ * render() {
62
+ * return <p>{this.props.version.deno}</p>
63
+ * }
64
+ * }
65
+ * export default withDeno(() => Deno.version)(MyComponent)
66
+ * ```
67
+ */
68
+ export function withDeno < T > ( callback : ( ) => ( T | Promise < T > ) , browser ?: boolean , deps ?: ReadonlyArray < any > ) {
69
+ return function < P extends T > ( Component : React . ComponentType < P > ) : React . ComponentType < Exclude < P , keyof T > > {
70
+ return function WithDeno ( props : Exclude < P , keyof T > ) {
71
+ const denoProps = useDeno ( callback , browser , deps )
72
+ if ( typeof denoProps === 'object' ) {
73
+ return React . createElement ( Component , { ...props , ...denoProps } )
74
+ }
75
+ return React . createElement ( Component , props )
76
+ }
77
+ }
78
+ }
You can’t perform that action at this time.
0 commit comments