docs: add `watchEffect` notes
Description of Problem
I have observed that users often make some mistakes when using watchEffect, such as asynchronously accessing reactive variables, resulting in dependencies not being collected, or having an if statement with a false condition during the initial execution, leading to uncollected dependencies. These errors can cause watchEffect to malfunction. In this pull request, I have added some notes to help users avoid these mistakes.
relate: https://github.com/vuejs/core/discussions/9773 https://github.com/vuejs/core/issues/9408 https://github.com/vuejs/core/issues/2093
Proposed Solution
Additional Information
My English is not very good. You can correct my grammar or inaccurate wording at will. Thank you.
Deploy Preview for vuejs ready!
| Name | Link |
|---|---|
| Latest commit | d5fc7f9c30f287bb11a4fc883e68c8f2c4dd4dc5 |
| Latest deploy log | https://app.netlify.com/sites/vuejs/deploys/65784d5ca334770008c89d1e |
| Deploy Preview | https://deploy-preview-2596--vuejs.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Hi, I saw this pull request and I would add this point from last comment by LinusBorg in https://github.com/vuejs/core/discussions/9773, I think it's very important and clear:
reactive dependencies are re-collected on each run of an effect. This is so that a) new dependencies, that might not have been accessed/read from in a previous run, can be read, and b) old dependencies, that are no longer being read from in the latest run, can be discarded.