You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -146,7 +144,7 @@ This reduces unnecessary effect triggers, but unfortunately doesn't work if the
146
144
```js
147
145
constcomputedObj=computed(() => {
148
146
return {
149
-
isEven:count.value%2===0?true:false
147
+
isEven:count.value%2===0
150
148
}
151
149
})
152
150
```
@@ -156,9 +154,9 @@ Because a new object is created each time, the new value is technically always d
156
154
Instead, we can optimize this by manually comparing the new value with the old value, and conditionally returning the old value if we know nothing has changed:
157
155
158
156
```js
159
-
constcomputedObj=computed(oldValue=> {
157
+
constcomputedObj=computed((oldValue)=> {
160
158
constnewValue= {
161
-
isEven:count.value%2===0?true:false
159
+
isEven:count.value%2===0
162
160
}
163
161
if (oldValue &&oldValue.isEven===newValue.isEven) {
Note that you should always perform the full computation before comparing and returning the old value, so that the same dependencies can be collected on every run.
0 commit comments