Skip to content

Fix docs mentions of the current value property #64

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/tests/useAsyncIterState.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('`useAsyncIterState` hook', () => {
}
);

it(gray("The state iterable's `.current.value` property is read-only"), async () => {
it(gray("The state iterable's `..value.current` property is read-only"), async () => {
const [values] = renderHook(() => useAsyncIterState<string>()).result.current;

expect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/AsyncIterableChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AsyncIterableChannel<T, TInit = T> {

/**
* A stateful async iterable which will yield every updated value following an update. Includes a
* `.current.value` property which shows the current up to date state value.
* `.value.current` property which shows the current up to date state value.
*
* This is a shared async iterable - all iterators obtained from it share the same source values,
* meaning that multiple iterators can be consumed (iterated) simultaneously and each one would pick up
Expand Down
18 changes: 9 additions & 9 deletions src/useAsyncIterState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export { useAsyncIterState, type AsyncIterStateResult, type AsyncIterableChannel
* ---
*
* The returned async iterable can be passed over to any level down the component tree and rendered
* using `<Iterate>`, `useAsyncIter`, and others. It also contains a `.current.value` property which shows
* using `<Iterate>`, `useAsyncIter`, and others. It also contains a `.value.current` property which shows
* the current up to date state value at all times. Use this any time you need to read the immediate
* current state (for example as part of side effect logic) rather than directly rendering it, since
* for rendering you may simply iterate values as part of an `<Iterate>`.
*
* Returned also alongside the async iterable is a function for updating the state. Calling it with a new
* value will cause the paired iterable to yield the updated state value as well as immediately set the
* iterable's `.current.value` property to that new state. Just like
* iterable's `.value.current` property to that new state. Just like
* [`React.useState`'s setter](https://react.dev/reference/react/useState#setstate), you can pass it
* the next state directly, or a function that calculates it from the previous state.
*
Expand All @@ -62,7 +62,7 @@ export { useAsyncIterState, type AsyncIterStateResult, type AsyncIterableChannel
*
* @example
* ```tsx
* // Use the state iterable's `.current.value` property to read the immediate current state:
* // Use the state iterable's `.value.current` property to read the immediate current state:
*
* import { useAsyncIterState } from 'react-async-iterators';
*
Expand All @@ -73,8 +73,8 @@ export { useAsyncIterState, type AsyncIterStateResult, type AsyncIterableChannel
* return (
* <form
* onSubmit={() => {
* const firstName = firstNameIter.current.value;
* const lastName = lastNameIter.current.value;
* const firstName = firstNameIter.value.current;
* const lastName = lastNameIter.value.current;
* // submit `firstName` and `lastName`...
* }}
* >
Expand All @@ -93,9 +93,9 @@ export { useAsyncIterState, type AsyncIterStateResult, type AsyncIterableChannel
* ---
*
* @template TVal the type of state to be set and yielded by returned iterable.
* @template TInitVal The type of the starting value for the state iterable's `.current.value` property.
* @template TInitVal The type of the starting value for the state iterable's `.value.current` property.
*
* @param initialValue Any optional starting value for the state iterable's `.current.value` property, defaults to `undefined`. You can pass an actual value, or a function that returns a value (which the hook will call once during mounting).
* @param initialValue Any optional starting value for the state iterable's `.value.current` property, defaults to `undefined`. You can pass an actual value, or a function that returns a value (which the hook will call once during mounting).
*
* @returns a stateful async iterable and a function with which to yield an update, both maintain stable references across re-renders.
*
Expand Down Expand Up @@ -146,7 +146,7 @@ type AsyncIterStateResult<TVal, TInitVal> = [
/**
* A stateful async iterable which yields every updated value following a state update.
*
* Includes a `.current.value` property which shows the current up to date state value at all times.
* Includes a `.value.current` property which shows the current up to date state value at all times.
*
* This is a shared async iterable - all iterators obtained from it share the same source values,
* meaning multiple iterators can be consumed (iterated) simultaneously, each one picking up the
Expand All @@ -156,7 +156,7 @@ type AsyncIterStateResult<TVal, TInitVal> = [

/**
* A function which updates the state, causing the paired async iterable to yield the updated state
* value and immediately sets its `.current.value` property to the latest state.
* value and immediately sets its `.value.current` property to the latest state.
*/
setValue: (update: MaybeFunction<TVal, [prevState: TVal | TInitVal]>) => void,
];
Loading