File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-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 > ;
You can’t perform that action at this time.
0 commit comments