File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ export { MaybeAsyncIterable } ;
2
+
3
+ /**
4
+ * Helper type that represents either a plain value or an async iterable of that value.
5
+ *
6
+ * This type is useful among else for typing props for components that can accept either a
7
+ * _"static" value_ or a _"changing" value_ (an async iterable) seamlessly.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { It, type MaybeAsyncIterable } from 'react-async-iterators';
12
+ *
13
+ * function MyComponent(props: { values: MaybeAsyncIterable<string[]> }) {
14
+ * return (
15
+ * <ul>
16
+ * <It value={props.values} initialValue={[]}>
17
+ * {next => next.value.map((item, idx) =>
18
+ * <li key={idx}>{item}</li>
19
+ * )}
20
+ * </It>
21
+ * </ul>
22
+ * );
23
+ * }
24
+ * ```
25
+ */
26
+ type MaybeAsyncIterable < T > = T | AsyncIterable < T > ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { useAsyncIter, type IterationResult } from './useAsyncIter/index.js';
2
2
import { Iterate , type IterateProps } from './Iterate/index.js' ;
3
3
import { iterateFormatted , type FixedRefFormattedIterable } from './iterateFormatted/index.js' ;
4
4
import { useAsyncIterState , type AsyncIterStateResult } from './useAsyncIterState/index.js' ;
5
+ import { type MaybeAsyncIterable } from './MaybeAsyncIterable/index.js' ;
5
6
6
7
export {
7
8
useAsyncIter ,
@@ -13,4 +14,5 @@ export {
13
14
type FixedRefFormattedIterable ,
14
15
useAsyncIterState ,
15
16
type AsyncIterStateResult ,
17
+ type MaybeAsyncIterable ,
16
18
} ;
You can’t perform that action at this time.
0 commit comments