Destructuring functional props remove reactivity ?
Non working example (direct destructuring) :
(filterableOptionsProps is a signal)
I was wondering if there is a better way than this to keep reactivity :
Is Split props the way to go ?
I could not get it work since my props are inside a signal i think ...
Any hint for a better solution is welcome !
Have a nice day !
10 Replies
Spreading props in jsx as fine. The problem is only when destructuring when accepting props to a function
splitProps (and mergeProps) is a solution to that latter case
The reason for the difference is that the compiler changes the semantics of the spread in jsx. Similar to how props in general are transformed into objects getters
If i understood correctly destructuring props coming from a function need splitProps ?
(i am having issue with my English as i cant really understand
The problem is only when destructuring when accepting props to a function
)
edit: Ah i might just understood : The issue is destructuring idividual prop form a spread syntaxe when those props are function ?
I my case the function is a signal so i cant properly use splitProps as it wont react to the signal changes ?
I would need to use createSignal or CreateMemo but the extracted value form calling splitProps would also be stored in a signal so we are back to the starting point ?
I must be doing something wrong ...In your example above, the correct way to do it is as shown in your first code snippet. No changes are necessary
Ok thanks i taught they was a more elegant way
edit : the first synipet doesn't work
In case it wasn't clear from what I wrote, this is expected to work
I'm not sure what could be more elegant
Unfortunatly this snippet doesn't work for me
If it isn't working it isn't because of the code shown. Something is wrong somewhere else
If you are destructuring in the definition of Select, that could be a problem, for example, but that code isn't shown
Which is to say, this would be a problem:
Do this instead
fileterableOptionsProps is a signal containing various props (functions)
i tested those function individualy using a another createEffect
but those function have a scope that will be initialised latter (when the signalfileterableOptionsProps is updated).
and the Select only retrive the initial function scope no the updated one
Select is a library but i could create my own and see if this is the issue thanks for the hints !
In that case, if the select component access those functions at the top level, that would cause the problem
Using a createMemo instead of a signal + createEffect for fileterableOptionsProps fixed my issue 🤷♂️
The destructuring work as itended now.