Skip to content

Commit e7eeaf1

Browse files
authored
Merge branch 'master' into fix-iters-formatted-to-undefined-issue
2 parents d3cbd95 + 3f08461 commit e7eeaf1

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/iterateFormatted/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ export { iterateFormatted };
5252
*
5353
* This utility should come handy in places when you need a formatted (or _"mapped"_) version of
5454
* some existing async iterable before passing it as prop into an other component which consumes it
55-
* and you rather have the transformation written right next to the place instead of far from it
56-
* in the top as some `useMemo` hook call.
55+
* and you rather have the formatting logic right at the place in code of passing the prop instead
56+
* of far from it having to do this transformation via some `useMemo` hook call at the top of the
57+
* component.
5758
*
5859
* The utility's method of operation is it will take `source` and return from it a new transformed
5960
* async iterable object with some special metadata attached that tells library tools like

src/useAsyncIter/index.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ export { useAsyncIter, type IterationResult };
1616
// TODO: The initial values should be able to be given as functions, having them called once on mount
1717

1818
/**
19-
* `useAsyncIter` hooks up a single async iterable value into your component and its lifecycle.
20-
*
21-
* _Illustration:_
19+
* `useAsyncIter` hooks up a single async iterable value to your component and its lifecycle.
2220
*
21+
* @example
2322
* ```tsx
2423
* import { useAsyncIter } from 'react-async-iterators';
2524
*
@@ -35,37 +34,37 @@ export { useAsyncIter, type IterationResult };
3534
* }
3635
* ```
3736
*
38-
* Given an async iterable `input`, this hook will iterate it and rerender the host component upon
39-
* each new value that becomes available together with any possible completion or error it may run into.
40-
* If `input` is a plain (non async iterable) value, it will simply be used to render once and
41-
* immediately.
37+
* Given an async iterable `input`, this hook will iterate it value-by-value and update (re-render) the
38+
* host component upon each yielded value, along with any possible completion or error it may run into.
39+
* `input` may also be given a plain (non async iterable) value, in which case it will simply be used
40+
* to render once and immediately, thus enabling components that can handle _"static"_ as well as
41+
* _"changing"_ values and props seamlessly.
4242
*
43-
* The hook inits and maintains its current iteration process with its given `input` async iterable
44-
* across re-renders as long as `input` is passed the same object reference each time (similar to
45-
* the behavior of a `useEffect(() => {...}, [input])`), therefore care should be taken to avoid
46-
* constantly recreating the iterable every render, e.g; by declaring it outside the component body,
47-
* control __when__ it should be recreated with React's
48-
* [`useMemo`](https://react.dev/reference/react/useMemo) or alternatively the library's
49-
* {@link iterateFormatted `iterateFormatted`} util for only formatting the values.
50-
* Whenever `useAsyncIter` detects a different `input` value, it automatically closes a previous
51-
* `input` async iterable before proceeding to iterate any new `input` async iterable. The hook will
52-
* also ensure closing a currently iterated `input` on component unmount.
43+
* The hook initializes and maintains its iteration process with its given async iterable `input`
44+
* across component updates as long as `input` keeps getting passed the same object reference every
45+
* time (similar to the behavior of a `useEffect(() => {...}, [input])`), therefore care should be taken
46+
* to avoid constantly recreating the iterable on every render, by e.g; declaring it outside the component
47+
* body, control __when__ it should be recreated with React's
48+
* [`useMemo`](https://react.dev/reference/react/useMemo) or alternatively use the library's
49+
* {@link iterateFormatted `iterateFormatted`} util for a formatted version of an iterable which
50+
* preserves its identity.
51+
* Whenever `useAsyncIter` detects a different `input` value, it automatically closes the previous
52+
* active async iterable and proceeds to start iteration with the new `input` async iterable. On
53+
* component unmount, the hook will also ensure closing any currently iterated `input`.
5354
*
5455
* The object returned from `useAsyncIter` holds all the state from the most recent iteration
5556
* of `input` (most recent value, whether is completed or still running, etc. - see
5657
* {@link IterationResult `IterationResult`}).
5758
* In case `input` is given a plain value, it will be delivered as-is within the returned
5859
* result object's `value` property.
5960
*
60-
* @template TVal The type of values yielded by the passed iterable or of a plain value passed otherwise.
61+
* @template TVal The type of values yielded by the passed iterable or type of plain value if otherwise passed.
6162
* @template TInitVal The type of the initial value, defaults to `undefined`.
6263
*
63-
* @param input Any async iterable or plain value
64-
* @param initialVal Any initial value for the hook to return prior to resolving the ___first
65-
* emission___ of the ___first given___ async iterable, defaults to `undefined`.
64+
* @param input Any async iterable or plain value.
65+
* @param initialVal Any initial value for the hook to return prior to resolving the ___first emission___ of the ___first given___ async iterable, defaults to `undefined`.
6666
*
67-
* @returns An object with properties reflecting the current state of the iterated async iterable
68-
* or plain value provided via `input` (see {@link IterationResult `IterationResult`})
67+
* @returns An object with properties reflecting the current state of the iterated async iterable or plain value provided via `input` (see {@link IterationResult `IterationResult`}).
6968
*
7069
* @see {@link IterationResult `IterationResult`}
7170
*

0 commit comments

Comments
 (0)