#Can't use `useRouteData`

19 messages · Page 1 of 1 (latest)

short cloud
#

Hi guys, I'm using basic routing without FileRouter and whenever I'm trying to use useRouteData inside of my component, I'm getting Make sure your app is wrapped in a <Router /> , without using it, everything works just fine. Do you have an idea what can be the issue? I've got a lazy component inside <Route component={

kindred garden
#

are you passing the data function to the data prop?

#

does it work when the component is not lazy?

short cloud
#

@kindred garden yes and no

#

I've tried without lazy import, nothing seems to work . Whenever I comment the useRouteData, query function runs as well and everything's fine.

#

I just want to know, what can be the cause of that kind of behaviour. I'm creating Solid components in kinda different way so to say, without JSX.

kindred garden
#

can you screenshot the router & component code?

#

from what I understand route data is a fully runtime mechanism, so JSX shouldn't be important

#

or, if you call useLocation or any other primitive that hooks into existing router in that component, do you get the same error, or is it only with useRouteData?

short cloud
#

For demonstration purposes I've moved Route component back to solid and now Component is PureScript generated component, which is being composed with the functions of second screen.

so basically my Component is a function, which returns createComponent and inside createComponent's function, I have useRouteData

kindred garden
#

how do you use dynamic?

#

this doesn't look right

#

I would always do

get children() {
  return cs
}
kindred garden
#

because if the children are executed too early - not by the <Router> but by the <Route> or something like that, none of the Router hooks will work

short cloud
#

I’m using dynamic to create basic dom nodes, div, span, etc…
Regarding children being executed before, when I’m logging something from that component, I only see those logs, whenever I’m getting redirected to that page, so I don’t think that they are executed earlier.

Will check it out a bit later, thanks for your time. I’ll get back soon.

short cloud
#

useLocation doesn't work as well, I guess something's executing too early and that's causing the issue?

#

@kindred garden

#

but that seems like illogical, my Router invocation is waay up there. I'm using SolidStart template and as you can see, that Component is being called even under Routes