paoloricciuti / sveltekit-search-params

The easiest way to read and WRITE from query parameters in sveltekit.
https://sveltekit-search-params.netlify.app
MIT License
550 stars 19 forks source link

Using update function from queryParam store doesn't update the url #9

Closed ilhamfu closed 1 year ago

ilhamfu commented 1 year ago

i notice this when i building my pagination component, i use this code const current_page = queryParam("page", ssp.number(1));\ and using this button to go to previous page ` <button class="grid place-items-center bg-white border-gray-600 shadow-md" on:click={() => current_page.update((e) => { const new_val = Math.max((e ?? 1) - 1, 1); return new_val; })}

< ` the current_page state gets updated but the brower url doesn't.

paoloricciuti commented 1 year ago

Duh I'm stupid...I COMPLETELY forgot to implement the update function because most of the time I use the $ syntax (which by the way I suggest you to use too)...you can just do this

<button class="grid place-items-center bg-white border-gray-600 shadow-md" on:click={() => {
    $current_page = Math.max(($current_page ?? 1) - 1, 1)
}} > &lt; </button>

Btw thanks for the issue, I'll implement the update function and republish again ;)

ilhamfu commented 1 year ago

i can live with that. i use update because that makes me feel safe whenever i want to update a state based on its previous value

paoloricciuti commented 1 year ago

You don't have to...I just fixed it and I'm gonna republish soon.

paoloricciuti commented 1 year ago

Let me know if it's fixed in 0.1.14 😉

paoloricciuti commented 1 year ago

The issue should be fixed know, closing for the moment...feel free to comment back if there's some sort of problem, I'll re-open the issue eventually.