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
Tommypop12mo 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
pacovelobs12mo 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
Tommypop12mo 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
pacovelobs12mo 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
Tommypop12mo 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
pacovelobs12mo 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
Tommypop12mo ago
Yeah, that should be ok export const [signal, setSignal] = createSignal(0); should work
pacovelobs
pacovelobs12mo ago
Works like a charm. Thanks a lot!
Tommypop
Tommypop12mo ago
Awesome :)
Want results from more Discord servers?
Add your server
More Posts
Nested For Loop?Quick Version: Every time a For loop runs I'd like for one item to be displayed from the first set oIs there some cases where createResource doesn't handle errors ?Hello, I have this particular case where I'm fetching data based on searchParams and I have a basicAre global signals ever reset between test runs?@lexlohr Sorry - another issue 😅 As I've described in another issue I have structured my applicatHow to have a default layout for all routes?I am using `@solidjs/router` and I want to have a default layout to have a default background color.Why does effect re-fire? How to use createStore values in effect correctly?Check out this component. Why does the effect refire when I'm only changing person.name.first? It Access native html dialogs show/close methods in clickHandlerHey folks, I am currently using native html dialogs inside my app and am accessing their show/closeUncaught ReferenceError: createDeepSignal is not definedNot really sure what I'm doing wrong here. I definitely have SolidJS >v1.5 and I'm using a close co__vite_ssr_import_0__.default is not a function only on API endpointsI am getting an error from my api end-points when importing a third party library in my API code. I Why is storageSignal possibly null?I am having trouble understanding why TypeScript thinks that this storageSignal `theme` can be null:Is there a way to debug how callbacks are called, when firing an event with testing-library?[SOLVED]Hey, I am having a hard time testing my code and would like to find out if and how some of my event