How to array.filter Signal with array and pass down as Signal
I have a component:
That's how I call it
This was working with solidstart and
routedata
/createServerDta$
, but now I have to use solidjs. I think it was working, because of ssr
I think my Combox createEffect
is never been called because options that I hand over is not a Signal anymore.
So what would be an optimal strategy?10 Replies
use createMemo for the filtered array
Sure!
Is that the most elegant way?
probably
tbh I'm still trying to understand whats the issue
effects definitely won't be called on the server because they are not meant to be used for state syncing
I know, but then I never really checked if the effect was working and it was probably not crucial for current state of progress.
So CombBox is a component, I would like to use it for different option[] kinds. I am not so sure about React anymore, I think would just rerender that complete ComboBox, on filter, so that might have worked in react?! But again I am not sure.
Finding my way back to think reactive, think solidjs.
idiomatic solid might be very similar to idiomatic react
but in react "just calling setState" will also kinda work, when here you always have to think about how to express the state with signals and memos
Is replacing effect with a memo solving the problem? or is there something more?
It works! thanks. Too easy 🙂
ah ok
I was taking about the other effect
here you could just add
() =>
before the prevoius expression and it would also work
if you destructure props then you have to pass them as functions for lazy accessI understand.
Haven't thought about createMemo inside Combobox. Sure, it would create the reactivity from the options by explicitly observing it.
Actually
But
<ComBoxy options={()=>categories.filter()}>
works. (obviously i have to adjust ComboBox and usage of options)cos "options" is a getter? i.e you should call it like
const optionsMemo = createMemo(() => options());
i guess..I solved this for now and understood a bit better reactivity of solidjs with help of thetarnav.
Last comment showed what would not work, when option is an array, but not a function or Accessor. This thread shows shows a few approaches I have tried out. Finally I am choosing comobobox prop option to be a function. If I just pass down an array it won't work, because of lazy load feature of solidjs.