-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add inclusion/exclusion filters for aircraft
- Loading branch information
Showing
12 changed files
with
540 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
interface AsyncStateLoading { | ||
loading: true; | ||
error: undefined; | ||
} | ||
|
||
interface AsyncStateDone { | ||
loading: false; | ||
error: undefined; | ||
} | ||
|
||
interface AsyncStateError { | ||
loading: false; | ||
error: unknown; | ||
} | ||
|
||
export type AsyncState = AsyncStateLoading | AsyncStateDone | AsyncStateError; | ||
|
||
export function useAsync<T>(initial: T, fn: () => Promise<T>, deps: React.DependencyList) { | ||
const [state, setState] = useState<AsyncState>({ | ||
loading: true, | ||
error: undefined, | ||
}); | ||
|
||
const [value, setValue] = useState(initial); | ||
|
||
useEffect(() => { | ||
setState({ loading: true, error: undefined }); | ||
fn() | ||
.then((r) => setValue(r)) | ||
.then(() => setState({ loading: false, error: undefined })) | ||
.catch((e) => setState({ loading: false, error: e })); | ||
}, deps); | ||
|
||
return [value, state] as const; | ||
} |
Oops, something went wrong.