logoESLint React
Rules

no-misused-capture-owner-stack

Prevents incorrect usage of 'captureOwnerStack'.

This rule is experimental and may change in the future or be removed. It is not recommended for use in production code at this time.

Full Name in eslint-plugin-react-x

react-x/no-misused-capture-owner-stack

Full Name in @eslint-react/eslint-plugin

@eslint-react/no-misused-capture-owner-stack

Features

๐Ÿงช

Presets

strict strict-typescript strict-type-checked

Rule Details

captureOwnerStack is only available in development builds of React and must be:

  1. Imported via a namespace to avoid direct named imports.
  2. Conditionally accessed within an if (process.env.NODE_ENV !== 'production') { ... } block to prevent execution in production environments.
  3. Called inside a React-controlled function (not implemented yet).

Common Violations

Invalid

// Failing: Using a named import directly
import { captureOwnerStack } from "react";
//       ^^^ Don't use named imports of `captureOwnerStack` in files that are bundled for development and production. Use a namespace import instead.

if (process.env.NODE_ENV !== "production") {
  const ownerStack = React.captureOwnerStack();
  console.log("Owner Stack", ownerStack);
}
// Failing: Missing environment check
import * as React from "react";

const ownerStack = React.captureOwnerStack();
//                 ^^^ `captureOwnerStack` should only be used in development builds. Use an environment check to ensure it is not executed in production.
console.log(ownerStack);

Valid

// Passing: Correct namespace import with environment check
import * as React from "react";

if (process.env.NODE_ENV !== "production") {
  const ownerStack = React.captureOwnerStack();
  console.log("Owner Stack", ownerStack);
}

Resources

Further Reading

On this page