Skip to content

docs: Include guidance for updating multiple query params at once #105

@ieedan

Description

@ieedan

Describe the problem

Currently there is no guidance for updating multiple query parameters at once. If you aren't sure of exactly sure of how the library works this can lead to unintended behavior and errors.

For instance if I have a date range component that should update 3 parameters simultaneously:

{
  period?: string;
  from?: number;
  to?: number;
}

In a change function I may make the mistake of writing it like:

const store = queryParameters();

const change = (value) => {
  $store.period = value.period;
  $store.from = value.from;
  $store.to = value.to;
}

In this case I would call goto() 3 times on the page causing the following error to appear in the browser:

sveltekit 'client.js Uncaught (in promise) Error: navigation aborted'

This could easily be avoided by using the update function on the store:

const store = queryParameters();

const change = (value) => {
  store.update(v => {
    return {
      ...v,
      period: value.period,
      start: value.start,
      end: value.end
    }
  })
}

Describe the proposed solution

Add documentation in the README with guidance on how to handle batch updating query parameters like shown above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions