S
SolidJSβ€’3y ago
arazorda

Search params reactivity in route's data loader function

I've got a problem with search params in route's data function. Basically I've got something like in the screenshot and whenever search param changes, effect is not run, so input value isn't changing. Do you guys know how can I make this work? SOLUTION: spreading search doesn't lose reactivity, so I've just spread search const and everything works as intended.
9 Replies
arazorda
arazordaOPβ€’3y ago
I'm using useRoutes from @solidjs/router
apollo79
apollo79β€’3y ago
The problem here is that search is a bit like a store in solid, meaning you have to access a property to get a reactive value
Lo | Building Dromo
Lo | Building Dromoβ€’3y ago
Here you go:
const input = createMemo(() => ({ return {search.query, params.type}}));

createEffect(() => console.log(input(), search());
const input = createMemo(() => ({ return {search.query, params.type}}));

createEffect(() => console.log(input(), search());
Not sure what you are trying to accomplish with type: params.type though
arazorda
arazordaOPβ€’3y ago
Thanks for the replies guys, @carlonyte search is not an accessor, so it's not callable @apollo79 seems like that's the case, but the problem is that, that search object can get quite big, there's no way to make it reactive somehow? I will have many properties there, basically I'm using it as a filter for some data.
apollo79
apollo79β€’3y ago
Well, one way would be accessing one property that you know it exists always I think destructurung search should work too as that accesses all properties (?)
Lo | Building Dromo
Lo | Building Dromoβ€’3y ago
Oh man. Yup I’m an idiot. Don’t know what I was thinking πŸ˜…
arazorda
arazordaOPβ€’3y ago
for now I did something like this πŸ˜…
arazorda
arazordaOPβ€’3y ago
heh, destructuring works, I was certain that I would lose reactivity, but seems like this is not the case thanks a lot
apollo79
apollo79β€’3y ago
Np πŸ‘

Did you find this page helpful?