Skip to content

watchEffect not triggering properly with reactive or ref objects #9428

Discussion options

You must be logged in to vote

Your watchEffects are not equivalent to the watch() variations.

  1. The First watch watches a reactive object, so a change to any of that object's properties (i.e. .count) will trigger it.
  2. The second one watches a ref, which by default would only react to a reassignment of the ref's .value - but you make it watch all of the nested properties as well with the deep option.
  3. Your first watchEffect watches nothing, it just logs the value of the stateReact variable. It accesses no reactive properties, so nothing is being watched, an nothing will ever make this effect run again.
  4. Your second watchEffect logs the ref's .value, so it will only run if you reassign the ref to a new value. No reactive pr…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
2 replies
@rafael-lua
Comment options

@LinusBorg
Comment options

Answer selected by rafael-lua
Comment options

You must be logged in to vote
1 reply
@LinusBorg
Comment options

Comment options

You must be logged in to vote
3 replies
@LinusBorg
Comment options

@bitrxjs
Comment options

@LinusBorg
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #9425 on October 19, 2023 06:19.