You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Iterate/index.tsx
+21-18Lines changed: 21 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -4,45 +4,45 @@ import { useAsyncIter, type IterationResult } from '../useAsyncIter/index.js';
4
4
export{Iterate,typeIterateProps};
5
5
6
6
/**
7
-
* The `<Iterate>` helper component (importable also as `<It>`) is used to format and render an async iterable
8
-
* (or a plain non-iterable value) directly onto a piece of UI.
7
+
* The `<Iterate>` helper component (also exported as `<It>`) is used to format and render an async
8
+
* iterable (or a plain non-iterable value) directly onto a piece of UI.
9
9
*
10
-
* Essentially wraps a single {@link useAsyncIter `useAsyncIter`} hook call into a component
10
+
* Essentially, can be seen as a {@link useAsyncIter `useAsyncIter`} hook in a component form,
11
11
* conveniently.
12
12
*
13
13
* _Illustration:_
14
14
*
15
15
* ```tsx
16
-
* import { Iterate } from 'react-async-iterators';
16
+
* import { It } from 'react-async-iterators';
17
17
*
18
18
* function SelfUpdatingTodoList(props) {
19
19
* return (
20
20
* <div>
21
21
* <h2>My TODOs</h2>
22
22
*
23
23
* <div>
24
-
* Last TODO was completed at: <Iterate>{props.lastCompletedTodoDate}</Iterate>
24
+
* Last TODO was completed at: <It>{props.lastCompletedTodoDate}</It>
25
25
* </div>
26
26
*
27
27
* <ul>
28
-
* <Iterate value={props.todosAsyncIter}>
28
+
* <It value={props.todosAsyncIter}>
29
29
* {({ value: todos }) =>
30
30
* todos?.map(todo =>
31
31
* <li key={todo.id}>{todo.text}</li>
32
32
* )
33
33
* }
34
-
* </Iterate>
34
+
* </It>
35
35
* </ul>
36
36
* </div>
37
37
* );
38
38
* }
39
39
* ```
40
40
*
41
-
* `<Iterate>` may be preferable over {@link useAsyncIter `useAsyncIter`} typically as the UI area
42
-
* it re-renders can be expressively confined to the minimum necessary, saving unrelated elements
43
-
* within UI of a larger component from re-evaluating. On the other hand, the
44
-
* counterpart {@link useAsyncIter `useAsyncIter`} being a hook has to re-render the entire
45
-
* component output for every new value.
41
+
* `<Iterate>` may be preferable over the {@link useAsyncIter `useAsyncIter`} counterpart typically as
42
+
* the UI area it re-renders within a component tree can be expressly confined to the necessary
43
+
* minimum, saving any other unrelated elements from re-evaluation - while on the other hand
44
+
* {@link useAsyncIter `useAsyncIter`} being a hook it has to re-render an entire
45
+
* component's output for every new value.
46
46
*
47
47
* Given an async iterable as the `value` prop, this component will iterate it and render each new
48
48
* value that becomes available together with any possible completion or error it may run into.
@@ -54,15 +54,16 @@ export { Iterate, type IterateProps };
54
54
* should be recreated with React's [`useMemo`](https://react.dev/reference/react/useMemo).
55
55
* `<Iterate>` will automatically close its iterated iterable as soon as it gets unmounted.
56
56
*
57
+
* ---
58
+
*
57
59
* @template TVal The type of values yielded by the passed iterable or otherwise type of the passed plain value itself.
58
60
* @template TInitialVal The type of the initial value, defaults to `undefined`.
59
61
*
60
62
* @param props Props for `<Iterate>`. See {@link IterateProps `IterateProps`}.
61
63
*
62
-
* @returns A React node that updates its contents in response to each next yielded value automatically as
63
-
* formatted by the function passed as `children` (or in the absent of, just the yielded values as-are).
64
+
* @returns A React node that re-renders itself with each yielded value, completion or error, and formatted by the child render function passed into `children` (or just the yielded value as-is in the absent of it).
* An optional initial value, defaults to `undefined`.
146
+
* An optional initial value, defaults to `undefined`. Will be the value provided inside the child
147
+
* render function when `<Iterate>` first renders on being mounted and while it's pending its first
148
+
* value to be yielded.
146
149
*/
147
150
initialValue?: TInitialVal;
148
151
/**
149
-
* A render function that is called for each iteration state and returns something to render
152
+
* A render function that is called for each step of the iteration, returning something to render
150
153
* out of it.
151
154
*
152
155
* @param nextIterationState - The current state of the iteration, including the yielded value, whether iteration is complete, any associated error, etc. (see {@link IterationResult `IterationResult`})
0 commit comments