How can I access root data?

Which I’ve defined in root.data.ts
14 Replies
Max
Max2y ago
Might need more detail, can you just export and import it where needed? What kind of data
aquarazorda
aquarazordaOP2y ago
@maxoucsgo I've found that, in StartClient, it's checking for root.data.ts and if it exports default function for fetching data, it fetches it, but I can't find a way to access that data, useRouteData doesn't return it
aquarazorda
aquarazordaOP2y ago
@thetarnav @lxsmnsyc maybe you know something about this? sorry for tagging this is from solid-start/entry-client/StartClient.tsx
aquarazorda
aquarazordaOP2y ago
that dataFn is fed to StartRouter
aquarazorda
aquarazordaOP2y ago
https://discord.com/channels/722131463138705510/722349143024205824/885899935290101823 const rootData = useData(0); this useData is no longer exported. @davedbase maybe you know up to date way to access root data
davedbase
davedbase2y ago
I’m not sure, perhaps the router mechanic changed and I have no idea
aquarazorda
aquarazordaOP2y ago
maybe @ryansolid knows how it can be used
ryansolid
ryansolid2y ago
Right.. it is probably about where it is used. Technically useRouteData should return it, but the read might need to happen lower down... it also feeds into the data property of child routeData's
aquarazorda
aquarazordaOP2y ago
thanks for the response. I've tried using useRouteData almost everywhere, can't find that root data anywhere
ryansolid
ryansolid2y ago
It gets passed through the routeData itself.. like you need to re-send it..
export const routeData = ({ data }) =>
export const routeData = ({ data }) =>
aquarazorda
aquarazordaOP2y ago
got it, thanks!
ryansolid
ryansolid2y ago
If there is no routeData for the route then it should just use that instead
aquarazorda
aquarazordaOP2y ago
What I was thinking was, that I have some external JSON for i18n, which holds language data. So I thought, I would've fetched it with root.data.ts and then pass it to i18n's provider via useRouteData.
ryansolid
ryansolid2y ago
Where is the provider? My gut here is if you have global context anyway there isn't much advantage in using the root data Like this is just a way to hoist stuff out it has no other special properties. You can fetch data anywhere, especially if the whole app basically depends on it.
Want results from more Discord servers?
Add your server