Skip to content

Commit

Permalink
doc: remove async from jotai-effect documentation (#2189)
Browse files Browse the repository at this point in the history
Co-authored-by: David Maskasky <[email protected]>
  • Loading branch information
dmaskasky and David Maskasky authored Oct 17, 2023
1 parent a8b9b42 commit 6ea4361
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions docs/integrations/effect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ yarn add jotai-effect
```ts
type CleanupFn = () => void

type EffectFn = (
get: Getter,
set: Setter
) => CleanupFn | void | Promise<CleanupFn | void>
type EffectFn = (get: Getter, set: Setter) => CleanupFn | void

function atomEffect(effectFn: EffectFn): Atom<void>
```
Expand Down Expand Up @@ -229,28 +226,6 @@ Aside from mount events, the effect runs when any of its dependencies change val

</details>

- **Async:**
For effects that return a promise, all atoms accessed with `get` prior to the returned promise resolving are added to the atom's internal dependency map. Atoms that have been watched after the promise has resolved, for instance in a `setTimeout`, are not included in the dependency map.

⚠️ Use [caution](https://github.com/jotaijs/jotai-effect/discussions/10) when using async effects

<!-- prettier-ignore -->
<details style="cursor: pointer; user-select: none;">
<summary>Example</summary>

```js
atomEffect(async (get, set) => {
await new Promise((resolve) => setTimeout(resolve, 1000))
// updates whenever `anAtom` changes value but not when `anotherAtom` changes value
get(anAtom)
setTimeout(() => {
get(anotherAtom)
}, 5000)
})
```

</details>

- **Cleanup:**
Accessing atoms with `get` in the cleanup function does not add them to the atom's internal dependency map.

Expand Down

1 comment on commit 6ea4361

@vercel
Copy link

@vercel vercel bot commented on 6ea4361 Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.