How to use a resource in a structure field as a reactive signal?
I am having serious skill issues and starting to lose my mind a bit.
Maybe someone has ideas how to make price reactive?
For now as far as I understand price field is created with NaN values because in the beginning of a page load I suppose the fetch is not yet executed because everything is async.
5 Replies
I think you could try to createStore to create a object signal. In the object, every attribute is reactive. On the other hand, if you want to some attribute to fetch data, just create an object including the signal what you have created. For instance:
isnt resource a signal itself? I suppose using resource to set value to another signal and using that in my structure would just do the same thing and would't update. Or am I missing something here?
normally i'll just use what the server returns and render out, and that's it, single resource is enough
the price is not included in the resource? and you have to get it somewhere else?
if you have control over the server, consider perform this logic on the server instead, the client's job is just getting data then render
By doing what you did,
You added an initial value to the signal. While the signal is reactive - the initial value is not.
So what you should do is just add the accessors of the resources without calling them
Like
…
price:testRubberPrice,
…
This way you keep the reactivity of the resources signals.
thank you guys! For some reason didn't think of passing accessor without their call, thanks!!!!
this would probably make my life a lot easier but I had made architectural mistakes so to say and just trying to finish things up so the code is weird and reason is missing 😅