Skip to content

Files

Latest commit

 

History

History
49 lines (36 loc) · 889 Bytes

no-env-in-context.md

File metadata and controls

49 lines (36 loc) · 889 Bytes

Pattern: Use of context.isServer/context.isClient in asyncData/fetch/nuxtServerInit

Issue: -

Description

This rule is for preventing using context.isServer/context.isClient in asyncData/fetch/nuxtServerInit.

Examples of incorrect code for this rule:

export default {
  asyncData(context) {
    if (context.isServer) {
      const foo = 'bar'
    }
  },
  fetch({ isClient }) {
    if (isClient) {
      const foo = 'bar'
    }
  }
}

Examples of correct code for this rule:

export default {
  async asyncData() {
    if (process.server) {
      const foo = 'bar'
    }
  },
  fetch() {
    if (process.client) {
      const foo = 'bar'
    }
  }
}

Further Reading