Skip to content

Commit f5e214b

Browse files
authored
feat: add default initial value parameters to useAsyncIterMulti and IterateMulti (#69)
1 parent 132ee05 commit f5e214b

File tree

5 files changed

+296
-176
lines changed

5 files changed

+296
-176
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,10 @@ It's similar to [`<It>`](#it), only it works with any changeable number of async
759759
An array of values to iterate over simultaneously, which may include any mix of async iterables or plain (non async iterable) values. Source values may be added, removed or changed at any time and new iterations will be close and started accordingly as per [Iteration lifecycle](#iteration-lifecycle).
760760

761761
- `initialValues`:
762-
An optional array of initial values. The values here will be the starting points for all the async iterables from `values` (correspondingly by matching array positions) while they are rendered by the `children` render function __for the first time__ and for each while it is __pending its first yield__. Async iterables from `values` that have no initial value corresponding to them will assume `undefined` as initial value.
762+
An _optional_ array of initial values. The values here will be the starting points for all the async iterables from `values` (by corresponding array positions) while they are rendered by the `children` render function __for the first time__ and for each while it is __pending its first yield__. Async iterables from `values` that have no initial value corresponding to them will assume `undefined` as initial value.
763+
764+
- `defaultInitialValue`:
765+
An _optional_ default starting value for every new async iterable in `values` if there is no corresponding one for it in the `initialValues` prop, defaults to `undefined`.
763766

764767
- `children`:
765768
A render function that is called on every progression in any of the running iterations, returning something to render for them. The function is called with an array of the combined iteration state objects of all sources currently given by the `values` prop (see [Iteration state properties breakdown](#iteration-state-properties-breakdown)).
@@ -843,7 +846,7 @@ It's similar to [`<It>`](#it), only it works with any changeable number of async
843846
<button onClick={addStaticValue}>🗿 Add Static Value</button>
844847

845848
<ul>
846-
<ItMulti values={inputs}>
849+
<ItMulti values={inputs} defaultInitialValue="">
847850
{states =>
848851
states.map((state, i) => (
849852
<li key={i}>
@@ -987,7 +990,11 @@ const [nextNum, nextStr, nextArr] = useAsyncIterMulti([numberIter, stringIter, a
987990
An _optional_ object with properties:
988991

989992
- `initialValues`:
990-
An _optional_ array of initial values. The values here will be the starting points for all the async iterables from `values` (correspondingly by matching array positions) while they are rendered by the `children` render function __for the first time__ and for each while it is __pending its first yield__. Async iterables from `values` that have no initial value corresponding to them will assume `undefined` as initial value.
993+
An _optional_ array of initial values. The values here will be the starting points for all the async iterables from `values` (by corresponding array positions) while they are rendered by the `children` render function __for the first time__ and for each while it is __pending its first yield__. Async iterables from `values` that have no initial value corresponding to them will assume `undefined` as initial value.
994+
995+
- `defaultInitialValue`:
996+
An _optional_ default starting value for every new async iterable in `values` if there is no corresponding one for it in `opts.initialValues`, defaults to `undefined`.
997+
991998

992999
### Returns
9931000

@@ -1073,7 +1080,7 @@ const [nextNum, nextStr, nextArr] = useAsyncIterMulti([numberIter, stringIter, a
10731080
function DynamicInputsComponent() {
10741081
const [inputs, setInputs] = useState<MaybeAsyncIterable<string>[]>([]);
10751082

1076-
const states = useAsyncIterMulti(inputs);
1083+
const states = useAsyncIterMulti(inputs, { defaultInitialValue: '' });
10771084

10781085
const addAsyncIterValue = () => {
10791086
const iterableValue = (async function* () {

0 commit comments

Comments
 (0)