Files
react.dev/src/content/reference/eslint-plugin-react-hooks/lints/gating.md
Lauren Tan eebeb0fcef React Compiler v1
Updates our blog posts and docs for React Compiler 1.0
2025-10-10 14:44:06 -04:00

1.4 KiB

title
title
gating

Validates configuration of gating mode.

Rule Details {/rule-details/}

Gating mode lets you gradually adopt React Compiler by marking specific components for optimization. This rule ensures your gating configuration is valid so the compiler knows which components to process.

Invalid {/invalid/}

Examples of incorrect code for this rule:

// ❌ Missing required fields
module.exports = {
  plugins: [
    ['babel-plugin-react-compiler', {
      gating: {
        importSpecifierName: '__experimental_useCompiler'
        // Missing 'source' field
      }
    }]
  ]
};

// ❌ Invalid gating type
module.exports = {
  plugins: [
    ['babel-plugin-react-compiler', {
      gating: '__experimental_useCompiler' // Should be object
    }]
  ]
};

Valid {/valid/}

Examples of correct code for this rule:

// ✅ Complete gating configuration
module.exports = {
  plugins: [
    ['babel-plugin-react-compiler', {
      gating: {
        importSpecifierName: 'isCompilerEnabled', // exported function name
        source: 'featureFlags' // module name
      }
    }]
  ]
};

// featureFlags.js
export function isCompilerEnabled() {
  // ...
}

// ✅ No gating (compile everything)
module.exports = {
  plugins: [
    ['babel-plugin-react-compiler', {
      // No gating field - compiles all components
    }]
  ]
};