Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Latest commit

 

History

History
52 lines (38 loc) · 914 Bytes

no-env-in-context.md

File metadata and controls

52 lines (38 loc) · 914 Bytes

nuxt/no-env-in-context

disallow context.isServer/context.isClient in asyncData/fetch/nuxtServerInit

  • ⚙️ This rule is included in "plugin:nuxt/base".

Rule Details

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'
    }
  }
}

🔍 Implementation