-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Reactivity issue with computed on array first item #12735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think the problem is that the first argument passed to reactive([{ a: 1 }, { b: 2 }]).reduce((c, d) => {
console.log(c, d)
})
No initial value is being passed to |
Your error is caused by how the "The first time that the callback is run there is no "return value of the previous calculation". If supplied, an initial value may be used in its place. Otherwise the array element at index 0 is used as the initial value and iteration starts from the next element (index 1 instead of index 0)." More can be found here. If you don't want your program to skip the first execution, you must pass the optional |
const maxBy = (arr, iteratee) => { |
It is indeed working by passing the first item as initial value optional parameter! Reactivity is working fine after fixing it. Thank you for your answers <3 |
Version
3.5.13
Reproduction link
stackblitz.com
Steps to reproduce
Click on the button "Increment first array item" until the first array item object reach 5.
The computed "biggestNumber" is never recomputed, showing 4 instead of 5.
Click once on the second button "Increment second array item". The computed "biggestNumber" is now recomputed and displays 5 as expected.
Click on the first button, this time the computed is always recomputed on each clicks.
Click on the second button until it's value is superior to the first array item. Then click on the first one, it loses reactivity again.
This only happens to the first array item, redo steps with the first button and third or first and fourth.
What is expected?
The computed should react to changes on the first array item.
What is actually happening?
The first item never triggers computed reactivity until other array items changes.
Thank you for your work, love Vue <3
The text was updated successfully, but these errors were encountered: