solidjs-community / solid-primitives

A library of high-quality primitives that extend SolidJS reactivity.
https://primitives.solidjs.community
MIT License
1.23k stars 122 forks source link

useLocationHash #427

Open jer3m01 opened 1 year ago

jer3m01 commented 1 year ago

Describe The Problem To Be Solved

reactively use location hash

Suggest A Solution

const locationHash = useLocationHash();

createEffect(() => {
  console.log(locationHash()); // => '#' + string
});

https://developer.mozilla.org/en-US/docs/Web/API/Window/hashchange_event

thetarnav commented 1 year ago

I was working on a url package long time ago, but dropped it because I didn't know what I was doing and solid-router provides similar functionality. But maybe it could be revived with a smaller, more focus scope. This it createLocationState which was kinda doing that: https://github.com/solidjs-community/solid-primitives/blob/url/packages/url/src/location.ts#L113