Update relevant DOM element based on signal. #1970
-
Hello people.
But I am also displaying it in the List component by passing the whole state.
In the chart component, i am plotting a simple chart with chartjs and whenever the value of list is changed, the chart is updated by using an effect `createEffect(() => {
}); The problem I am facing is that, whenever I change the cart name in the parent component, the effect runs and plot gets updated. I would want to avoid that but only update the plot when the list changes. How can i seem to solve it? Coming from react background, I seem to be a bit lost here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The reason the effect runs on name change is that the entire cart is in one signal. So when any part of that object is updated anything listening to the signal is updated. The simple way to solve this is to just use two signals instead of one. const [name, setName]=createSignal('');
const [cartList, setCartList]=createSignal([{itemName:"", itemPrice:""}]); Or if you want to keep everything in one object, take a look at the stores api. |
Beta Was this translation helpful? Give feedback.
The reason the effect runs on name change is that the entire cart is in one signal. So when any part of that object is updated anything listening to the signal is updated.
The simple way to solve this is to just use two signals instead of one.
Or if you want to keep everything in one object, take a look at the stores api.
https://www.solidjs.com/tutorial/stores_nested_reactivity