Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

Sync state with URL params in Remix

by Roy Revelt   ·   posted on Monday, 01 August 2022   ·   reactremixts

This weekend I was tinkering with string-strip-html GUI; I wanted to sync the state with URL params so that users could bookmark the page and visit later and automatically get those settings restored.

Here’s an MVP based on a forked Remix.js starter template on StackBlitz.


Open it in a new tab, from within StackBlitz, so that there are no iframes, then change the checkboxes and observe the URL of the page:

Notes:

  • The useEffect sets the state according to the URL’s parameters. From there on, UI toggles update the state and set the URL parameters imperatively.
  • If we used <Link to=""> instead of <a href=""> in preset links, the page would not reload, so URL’s params would not update. Link presets here to emulate the visitor opening the page from fresh, in a new tab.

↑ back to top
older newer

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab