Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Doc atom effect no async #2189

Merged
merged 1 commit into from
Oct 17, 2023
Merged
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
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