S
SolidJS9mo ago
zishh

Custom signal for observable props parameter - Reactivity issue

have library which contains objects with observable properties. To make this work with solid I want to create a custom signal which triggers the reactive functionality. Basically something like this: https://playground.solidjs.com/anonymous/749a49e0-da6f-465b-995a-947e7d6bbdf9 Changing the observable value (by clicking the "Update" button) works fine. But the observable itself can change also change (by clicking the "Reset" button) and because props.observable is not called in a tracked context, we lose reactivity i.e. updates no longer have a visible effect. So I understand why this is happening but I do not know what the best way to solve this looks like. I thought about passing a function which returns the observable to createCustomSignal instead of the value itself. But I do not know what the implementation of createCustomSignal would then look like such that it can track changes. Any ideas how to make this work?
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
2 Replies
zishh
zishh9mo ago
Ugly "solution" https://playground.solidjs.com/anonymous/40bc52e2-117d-4f4c-b755-da632491c92d I guess this is not the intended way?
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
zishh
zishh9mo ago
@Toka Thanks that looks much better - Was not aware that I can put createEffect in the from creation. Issue with that code is that custom().unsubscribe(...) is not called. I guess it is only called onCleanup? Huh - I guess I have to read up on the API. I thought on is only necessary to make dependencies explicit. It is necessary here to get the previous value no? Got it working. Thank you!
Want results from more Discord servers?
Add your server
More Posts