File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { ModelState } from './Signum.Entities'
2
2
import { GraphExplorer } from './Reflection'
3
+ import * as React from 'react'
3
4
4
5
export interface AjaxOptions {
5
6
url : string ;
@@ -383,3 +384,24 @@ export class AbortableRequest<Q, A> {
383
384
} ) as Promise < A > ;
384
385
}
385
386
}
387
+
388
+
389
+ export function useAPI < T > ( defaultValue : T , key : ReadonlyArray < any > | undefined , makeCall : ( signal : AbortSignal ) => Promise < T > ) : T {
390
+
391
+ const [ data , updateData ] = React . useState < T > ( defaultValue )
392
+
393
+ React . useEffect ( ( ) => {
394
+ var abortController = new AbortController ( ) ;
395
+
396
+ makeCall ( abortController . signal )
397
+ . then ( result => updateData ( result ) )
398
+ . done ( ) ;
399
+
400
+ return ( ) => {
401
+ abortController . abort ( ) ;
402
+ }
403
+ } , key ) ;
404
+
405
+ return data ;
406
+
407
+ }
You can’t perform that action at this time.
0 commit comments