Skip to content

Commit

Permalink
doc: Add disclaimer about multiple updates
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Jan 27, 2022
1 parent f79a50a commit d0e9385
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ useQueryState('foo', { history: 'push' })

Any other value for the `history` option will fallback to the default.

## Multiple Queries

Because the Next.js router has asynchronous methods, if you want to do multiple
query updates in one go, you'll have to `await` them, otherwise the latter will
overwrite the updates of the former:

```ts
const MultipleQueriesDemo = () => {
const [lat, setLat] = useQueryState('lat', queryTypes.float)
const [lng, setLng] = useQueryState('lng', queryTypes.float)
const randomCoordinates = React.useCallback(async () => {
await setLat(Math.random() * 180 - 90)
await setLng(Math.random() * 360 - 180)
}, [])
}
```

_Note: support to synchronously update multiple related queries at the same time will come in a future update. See #277._

## Caveats

Because the Next.js router is not available in an SSR context, this
Expand Down

0 comments on commit d0e9385

Please sign in to comment.