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
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
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 🙏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
Well, this might be even smarter.
I'm hosting the app on gitlab pages so no SSR at all on the road-map.
Yeah, you might want to use context anyway, just in case you ever transition to SSR, but global signals should work fine in CSR
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.Yeah, that should be ok
export const [signal, setSignal] = createSignal(0);
should workWorks like a charm.
Thanks a lot!
Awesome :)