-
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 an exposed
MaybeAsyncIterable
helper generic type
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export { MaybeAsyncIterable }; | ||
|
||
/** | ||
* Helper type that represents either a plain value or an async iterable of that value. | ||
* | ||
* This type is useful among else for typing props for components that can accept either a | ||
* _"static" value_ or a _"changing" value_ (an async iterable) seamlessly. | ||
* | ||
* @example | ||
* ```tsx | ||
* import { It, type MaybeAsyncIterable } from 'react-async-iterators'; | ||
* | ||
* function MyComponent(props: { values: MaybeAsyncIterable<string[]> }) { | ||
* return ( | ||
* <ul> | ||
* <It value={props.values} initialValue={[]}> | ||
* {next => next.value.map((item, idx) => | ||
* <li key={idx}>{item}</li> | ||
* )} | ||
* </It> | ||
* </ul> | ||
* ); | ||
* } | ||
* ``` | ||
*/ | ||
type MaybeAsyncIterable<T> = T | AsyncIterable<T>; |