Subscribe on changes!

isOnSetup

avatar
Dec 21st 2021

What problem does this feature solve?

To distinguish whether codes are in a setup context. Setup is called only once, and its return is called multiple times due to dependency changes. Some apis need to be restricted to setup OnMounted is automatically called in setup,onScopeDispose needs to be manually disposed and used separately

What does the proposed API look like?

if(isOnSetup()){}else{}

avatar
Dec 21st 2021

You can use getCurrentInstance() to detect if you can call onMounted() and other composition api functions. Maybe you are putting things inside of the function returned in setup while they should be outside:

setup() {
  return () => {
    const data = ref() // this should go up
    // ... return jsx
  }
}