confused about primitives(useEffect,on,createComputed)
I‘m trying to create a primitive for synchronize the search params with signal. I tried different methods, all of them works as expected. I started to think of the apis and got confused.
createEffect
in this case run twice
createEffect with on
run once
createComputed
run twice
1. why some of them run twice?
2. when to use on with effect?
3. tracking signal and do some updates, shoud I just use computed?
6 Replies
what’s useSearchParams?
from solid router
why do you need another primitive to manage a single parameter? couldn’t you just use the search params one directly?
I think it will, similarly to a store, hold signals for each search param, so you’re just repeating work that it does
if you really need that api
you could write it like this (If I understand how useSearchParams work)
but you see how unnecessary that is
Everytime the state chagnes, I need to update the search param. Also for shared link, I need the param to initialize the state.
also,
value => setSearchParams(param, value)
is not type setter. useSearchParams is not reactive..can't you just use the param as the state?
the types for
solid.Setter
are a bit complicated, but this should work, you can just typecast itI see. I will try your solution.