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';
22import { Iterate , type IterateProps } from './Iterate/index.js' ;
33import { iterateFormatted , type FixedRefFormattedIterable } from './iterateFormatted/index.js' ;
44import { useAsyncIterState , type AsyncIterStateResult } from './useAsyncIterState/index.js' ;
5+ import { type MaybeAsyncIterable } from './MaybeAsyncIterable/index.js' ;
56
67export {
78 useAsyncIter ,
@@ -13,4 +14,5 @@ export {
1314 type FixedRefFormattedIterable ,
1415 useAsyncIterState ,
1516 type AsyncIterStateResult ,
17+ type MaybeAsyncIterable ,
1618} ;
You can’t perform that action at this time.
0 commit comments