SolidJSS
SolidJS14mo ago
37 replies
jack

dealing with data shared between pages

this kind of seems like a common question among meta frameworks w/ routing built in of, "how do i share data from one page to the next". in this case, the cache doesn't help as this really only dedups for a single round trip more or less

the scenario i'm dealing with, which i would appreciate advice, is follows:

i have a dashboard page where i fetch all of the groups the user belongs to, and i display them as cards. if the user clicks a card, it brings them to /groups/[groupId]. here i render out a heading with the group name (which of course i already fetched on the previous page) and then all the rest of the page, which takes a bit to render due to fetching im waiting on. it is a nice touch if the heading renders while the rest of the page loads via suspense. this seems like a no brainer as i already have the data i wanna show.. i just don't know the best way to get it where i need it

my current hack is, on pointerdown of the cards that trigger nav, i update a global object like so navigation.lastClickedGroupName = group.name, and then i read that on the next page. i originally was using a global signal, but i realized i don't think i really need reactivity, so just went to a regular object

my question is, this feels super hacky. it's starting to feel like a global store is kind of what i ultimately need. is that the solution here since i have significant state needs across pages? basically just want to know what would be a best practice
Was this page helpful?