Skip to content

Files

Latest commit

 

History

History
86 lines (66 loc) · 1.76 KB

no-setup-props-destructure.md

File metadata and controls

86 lines (66 loc) · 1.76 KB

Pattern: Destructuring of props passed to setup

Issue: -

Description

This rule reports the destructuring of props passed to setup causing the value to lose reactivity.

<script>
export default {
  /* ✓ GOOD */
  setup(props) {
    watch(() => {
      console.log(props.count)
    })

    return () => {
      return h('div', props.count)
    }
  }
}
</script>

Destructuring the props passed to setup will cause the value to lose reactivity.

<script>
export default {
  /* ✗ BAD */
  setup({ count }) {
    watch(() => {
      console.log(count) // not going to detect changes
    })

    return () => {
      return h('div', count) // not going to update
    }
  }
}
</script>

Also, destructuring in root scope of setup() should error, but ok inside nested callbacks or returned render functions:

<script>
export default {
  setup(props) {
    /* ✗ BAD */
    const { count } = props

    watch(() => {
      /* ✓ GOOD */
      const { count } = props
      console.log(count)
    })

    return () => {
      /* ✓ GOOD */
      const { count } = props
      return h('div', count)
    }
  }
}
</script>

Further Reading