S
SolidJSβ€’12mo ago
aquarazorda

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
aquarazorda
aquarazordaβ€’12mo ago
I'm using useRoutes from @solidjs/router
apollo79
apollo79β€’12mo 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
Carlo Nyte
Carlo Nyteβ€’12mo 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
aquarazorda
aquarazordaβ€’12mo 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β€’12mo 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 (?)
Carlo Nyte
Carlo Nyteβ€’12mo ago
Oh man. Yup I’m an idiot. Don’t know what I was thinking πŸ˜…
aquarazorda
aquarazordaβ€’12mo ago
for now I did something like this πŸ˜…
aquarazorda
aquarazordaβ€’12mo 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β€’12mo ago
Np πŸ‘
Want results from more Discord servers?
Add your server
More Posts