FileRoutes props for app-wide signals

Hey there. I'm rewriting a small SPA from Yew (Rust 🦀) to Solid with SolidStart. In my Yew app, I have a bunch of app-wide properties. They're defined at the App level (equivalent of the root.tsx here). And passed to basically every pages through the routing functions. Here, the only way to do this would be to pass my getters/setters to the FileRoutes component. Which is not allowed. What would be the correct way to deal with this situation in a Solid SPA ? Thanks in advance!
P.
9 Replies
Tommypop
Tommypop2y ago
You'd probably want to use a context provider: https://docs.solidjs.com/references/concepts/state-management/context You can consume that context from anywhere within the app (provided that you wrap the entire app with the context provider) And you can just pass your getters and setters as context
pacovelobs
pacovelobsOP2y ago
All right. This is also available in Yew but I preferred to endure the props drilling than to fight the borrow-checker at run-time. It might be smarter to use contexts with Solid. Will do. Thanks for your quick reply 🙏
Tommypop
Tommypop2y ago
You're welcome :). If you're just using client-side rendering, you can just export a signal from a file and use it anywhere, but that doesn't play well with SSR at all
pacovelobs
pacovelobsOP2y ago
Well, this might be even smarter. I'm hosting the app on gitlab pages so no SSR at all on the road-map.
Tommypop
Tommypop2y ago
Yeah, you might want to use context anyway, just in case you ever transition to SSR, but global signals should work fine in CSR
pacovelobs
pacovelobsOP2y ago
Those are 100% front-end related, server will never know about. It's a color picker and it does not deal with backend at all. A fully static site in the making. So, basically, a single file in ~/components with getters and setters would be enough.
Tommypop
Tommypop2y ago
Yeah, that should be ok export const [signal, setSignal] = createSignal(0); should work
pacovelobs
pacovelobsOP2y ago
Works like a charm. Thanks a lot!
Tommypop
Tommypop2y ago
Awesome :)
Want results from more Discord servers?
Add your server