Remove element from store not working
I'm trying to remove an element from a reactive store based on the index. I've tried versions of this but I keep getting an error telling me "Cannot mutate a Store directly":
I've tried both <For> and <Index>
I've also tried something like
props.setMyFilter(i(),undefined)
but this does not result in any change in the DOM, but it does log an error because it is trying to render a element from the store that is no longer there.
3 Replies
Splice mutates an array in-place that's why you get the error.
You'll have to go with something like
props.setMyFilter(i(),undefined)
however this is not producing the result you expect.
Imagine an Array: [0, 1, 2, 3] with the way you're calling it, it would be (i = 2) [0, 1, undefined, 3]. What you really want, I'm assuming, is [0, 1, 3].
Try
Or if you prefer this:
Oh ok, thx for your help!
or
setMyFilter(produce(v => v.splice(i(), 1)))