Skip to content

Commit 3f08461

Browse files
authored
docs: various docs edits (#31)
1 parent 933760a commit 3f08461

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
@@ -15,10 +15,9 @@ export { useAsyncIter, type IterationResult };
1515
// TODO: The initial values should be able to be given as functions, having them called once on mount
1616

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

0 commit comments

Comments
 (0)