Skip to content

Commit

Permalink
fix(docs): async guide (pmndrs#1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Aug 11, 2022
1 parent d638899 commit be88cd3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/guides/async.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ const asyncIncrementAtom = atom(null, async (get, set) => {

const Component = () => {
const [, increment] = useAtom(asyncIncrementAtom)
React.useEffect(() => {
const handleClick = () => {
increment()
}, [])
}
// ...
}
```

Expand All @@ -102,9 +103,10 @@ const request = async () => fetch('https://...').then((res) => res.json())
const baseAtom = atom(0)
const Component = () => {
const [value, setValue] = useAtom(baseAtom)
React.useEffect(() => {
const handleClick = () => {
setValue(request()) // Will suspend until request resolves
}, [])
}
// ...
}
```

Expand Down

0 comments on commit be88cd3

Please sign in to comment.