T
TanStack•3mo ago
fair-rose

Fetching data in the page loader using an ID stored in localStorage

Hi guys ! 👋 First, i'm sorry if a similar question has already been asked, there a lot of posts and i couldn't find one related. Here is the context of my app: - It's a school management app for students, professor and administrator - An admin can manage multiple schools - To do that, in the sidebar, they can switch from a school to another and the data will change accordingly At the moment, we are storing the school id in the localStorage so the user can close the tab, come back later and still see the data related to the school they were on before. So obviously, every requests need that school id, to get the related classes, courses, subjects, etc. My question is, how would you handle the data fetching in the page loader in this context ? Because once the page is loaded, if the user change school from the sidebar, the loader function won't re run. Right now we are using a simple react provider, exporting a hook, which cannot be used in the page loader function, so all the data is fetched in the page body
2 Replies
metropolitan-bronze
metropolitan-bronze•3mo ago
I would put the school id in a path param. whenever the path param changes, then persist it in local storage
fair-rose
fair-roseOP•3mo ago
Haven't thought about that but it seems perfect, nice 🙂 thank you !

Did you find this page helpful?