Problem with updating :class #1699
-
So this one is kinda hard for me to explain, but I do have an example, but when I have an array that I'm using x-for on and I want to highlight the "current" value so I use :class to make that happen. Now whenever the current changes, the array gets updated with new items (I'm using this to create a pagination component), it starts highlighting what seems to be random elements, but upon closer inspection it seems that :class updates after changing the current, but not when the x-for updates. Now, depending on the order (this I found out while making the example) this either works well or not at all.
So the example above replicates the problem, if you increment or decrement it will highlight seemingly random items. But if we change the order of the code in the setCurrent function, it works fine. Note: my code worked in v2, only noticed the problem after upgrading, and so does the example. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I’m not sure I understand your intent, but you need |
Beta Was this translation helpful? Give feedback.
I’m not sure I understand your intent, but you need
:key
and I’d move display into a pure function just to simplify state (it’s just a calculation based on currIx so in this example it makes more sense but not sure your intent exactly). https://codepen.io/danddanddand/pen/JjNoQZY