S
SolidJS•2y ago
Grahf

Route Data to Pass Signal to Children Components

Hi. I'm trying to pass a signal from a great grandparent to a its great grand children. In (home).jsx I have this: const [selectedFont, setSelectedFont] = createSignal('inter') export function routeData() { return selectedFont() } In the great grand child I have this: const font = useRouteData() createEffect(() => { console.log(font) }) But font is never updated in the great grand child. The great grand child gets the original value(inter) but it doesn't appear to be updating. I've confirmed it's changing in (home).jsx. I also tried to using createRouteData() in (home).jsx
8 Replies
thetarnav
thetarnav•2y ago
1. you shouldn't really use global signals in a SSR env. you are risking hydration mismatches and srate leaking on the server 2. your effect is not subscribing to anything, it doesn't read from a signal
Grahf
GrahfOP•2y ago
is there someway to get a signal from (home).jsx to a file deep in the (home) folder?
thetarnav
thetarnav•2y ago
preferably through context, this way you're making sure that each request will have it's own copy of the state
Grahf
GrahfOP•2y ago
I also set up a context provider but I'm not sure which component I should wrap with the provider. Like with SolidJS I would wrap the <App /> component in the provider. I tried wrapping <FileRoutes /> in the provider but that didn't seem to be good.
thetarnav
thetarnav•2y ago
don't wrap FileRoutes becuse it doesn't render anything wrap <Router> or <Routes> maybe
Grahf
GrahfOP•2y ago
Dang... wrapped <Routes> and it works. Yesterday I tried wrapping <Outlet /> and a few other components too. I guess I could have kept guessing and would have eventually picked the right component.
thetarnav
thetarnav•2y ago
I would guess that if you have an Outlet, wrapping it should also work 🤔 need to see how it works
Grahf
GrahfOP•2y ago
In my case wrapping the <Outlet /> probably doesn't work because I'm using the provider in the component that <Outlet /> is in
Want results from more Discord servers?
Add your server