Skip to content

Commit

Permalink
Fix documentation for useAtomCallback.
Browse files Browse the repository at this point in the history
See #2149. The docs were for Jotai v1; update
for v2. The change is that the callback function passed to `useAtomCallback` no longer
returns a Promise; it just returns the atom value.
  • Loading branch information
stevemolitor committed Sep 27, 2023
1 parent f32e4e4 commit 6a819a5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/utilities/callback.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Ref: https://github.com/pmndrs/jotai/issues/60
### Usage

```ts
useAtomCallback(
callback: (get: Getter, set: Setter, arg: Arg) => Result
): (arg: Arg) => Promise<Result>
useAtomCallback<Result, Args extends unknown[]>(
callback: (get: Getter, set: Setter, ...arg: Args) => Result,
options?: Options
): (...args: Args) => Result
```
This hook allows to interact with atoms imperatively.
It takes a callback function that works like atom write function,
and returns a function that returns a promise.
This hook is for interacting with atoms imperatively. It takes a callback function that
works like atom write function, and returns a function that returns an atom value.
The callback to pass in the hook must be stable (should be wrapped with useCallback).
Expand Down Expand Up @@ -52,7 +52,7 @@ const Monitor = () => {
)
useEffect(() => {
const timer = setInterval(async () => {
console.log(await readCount())
console.log(readCount())
}, 1000)
return () => {
clearInterval(timer)
Expand Down

0 comments on commit 6a819a5

Please sign in to comment.