1👍
✅
default effect of watchEffect
is pre
which means in sequence of changes it will call first and last
watchEffect
calls itself for the first time and since it ispre
it will run immediatelystate.count++
is called andwatchEffect
notices the changestate.name = '...'
is called butwatchEffect
doesn’t careend main task
watchEffect
sees the change complete it calls the last time of the reaction cycle aspre
why
console.log(
Name :…)
runs twice in a row is due to the nature of the asynchronous function being put into a separate task you can refer to elsewhere
to make
watchEffect
call only once in the react cycle add{ flush: 'post' }
Source:stackexchange.com