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

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

Open
ieedan opened this issue Aug 27, 2024 · 0 comments · May be fixed by #107
Open

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

ieedan opened this issue Aug 27, 2024 · 0 comments · May be fixed by #107

Comments

@ieedan
Copy link

ieedan commented Aug 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant