Skip to content

Commit

Permalink
fix docs mentions of the current value property from .current.value
Browse files Browse the repository at this point in the history
… to `.value.current`
  • Loading branch information
shtaif committed Jan 23, 2025
1 parent c4174ee commit 693be7c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
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,
];

0 comments on commit 693be7c

Please sign in to comment.