Skip to content

Commit c7098d0

Browse files
committed
get ready for publish
1 parent dbbb537 commit c7098d0

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ declare function useResult<T, TDeps extends any[]>(
2323
import {useResult} from "@repeaterjs/react-hooks";
2424

2525
const result = useResult(async function *() {
26-
/* async generator body */
26+
/* ... */
2727
});
2828
```
2929

30-
`callback` is a function which returns an async iterator, usually an async generator function. The callback is called when the component initializes and the returned iterator updates the component as it produces results. `useResult` returns an `IteratorResult`, an object of type `{value: T, done: boolean}`, where `T` is the type of the produced values, and `done` indicates whether the iterator has returned. The first return value from this hook will be `undefined`, indicating that the iterator has yet to produce any values.
30+
`callback` is a function which returns an async iterator, usually an async generator function. The callback is called when the component initializes and the returned iterator updates the component whenever it produces results. `useResult` returns an `IteratorResult`, an object of type `{value: T, done: boolean}`, where `T` is the type of the produced values, and `done` indicates whether the iterator has returned. The first return value from this hook will be `undefined`, indicating that the iterator has yet to produce any values.
3131

3232
```ts
3333
function Timer() {
@@ -68,6 +68,12 @@ declare function useValue<T, TDeps extends any[]>(
6868
callback: (deps: AsyncIterableIterator<TDeps>) => AsyncIterableIterator<T>,
6969
deps?: TDeps,
7070
): T | undefined;
71+
72+
import {useValue} from "@repeaterjs/react-hooks";
73+
74+
const value = useValue(async function *() {
75+
/* ... */
76+
});
7177
```
7278

7379
Similar to `useResult`, except the `IteratorResult`’s value is returned rather than the `IteratorResult` object itself. Prefer `useValue` over `useResult` when you don’t need to distinguish between whether values were yielded or returned.
@@ -81,9 +87,12 @@ declare function useAsyncIter<T, TDeps extends any[]>(
8187

8288
import {useAsyncIter} from "@repeaterjs/react-hooks";
8389

84-
const iter = useAsyncIter(async function *() {
85-
/* async generator body */
86-
});
90+
function MyComponent() {
91+
const iter = useAsyncIter(async function *() {
92+
/* ... */
93+
});
94+
/* ... */
95+
}
8796
```
8897

8998
Similar to `useResult` and `useValue`, except that `useAsyncIter` returns the async iterator itself rather than consuming it. The returned async iterator can be referenced via closure in further `useResult` calls. Prefer `useAsyncIter` over `useResult` or `useValue` when you want to use an async iterator without updating each time a value is produced.
@@ -135,6 +144,12 @@ declare function useRepeater<T>(
135144
): [Repeater<T>, Push<T>, Stop];
136145

137146
import { useRepeater } from "@repeaterjs/react-hooks";
147+
import { SlidingBuffer } from "@repeaterjs/repeater";
148+
149+
function MyComponent() {
150+
const [repeater, push, stop] = useRepeater(new SlidingBuffer(10));
151+
/* ... */
152+
}
138153
```
139154

140155
Creates a repeater which can be used in useResult callbacks. `push` and `stop`

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "@repeaterjs/react-hooks",
33
"version": "0.1.0",
4-
"private": true,
54
"description": "React hooks for using async iterators in components",
65
"repository": {
76
"type": "git",

0 commit comments

Comments
 (0)