A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/signumsoftware/framework/commit/9ae1966a4c7b835093f69e44c2f17a31e9415a67 below:

add useAPI · signumsoftware/framework@9ae1966 · GitHub

File tree Expand file treeCollapse file tree 1 file changed

+22

-0

lines changed

Filter options

Expand file treeCollapse file tree 1 file changed

+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