+22
-0
lines changedFilter options
+22
-0
lines changed Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4