Skip to main content
ESLint Interlace
Plugin: react-featuresRules

react-no-inline-functions

react-no-inline-functions rule

Keywords: React, performance, ESLint rule, inline functions, useCallback, React optimization, re-renders, auto-fix, LLM-optimized, React performance

Prevent inline functions in React renders with performance metrics. This rule is part of eslint-plugin-react-features and provides LLM-optimized error messages with fix suggestions.

💡 Provides suggestions | 🔧 Automatically fixable

Quick Summary

AspectDetails
SeverityWarning (performance best practice)
Auto-Fix✅ Yes (suggests useCallback)
CategoryReact / Performance
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForReact/Next.js applications, performance-critical components

Rule Details

Detects inline functions in React JSX that cause unnecessary re-renders, providing performance impact analysis.

Configuration

OptionTypeDefaultDescription
allowInEventHandlersbooleanfalseAllow inline functions in event handlers
minArraySizenumber10Minimum array size to report inline functions in .map()

Examples

❌ Incorrect

function TodoList({ todos }: Props) {
  return (
    <div>
      {todos.map((todo) => (
        <TodoItem
          key={todo.id}
          todo={todo}
          onDelete={() => deleteTodo(todo.id)}  // ❌ Inline function
        />
      ))}
    </div>
  );
}

✅ Correct

function MyComponent() { return <div>Hello</div>; }

Configuration Examples

ESLint 9+ (Flat Config)

import reactFeatures from 'eslint-plugin-react-features';
import type { ReactNoInlineFunctionsOptions } from 'eslint-plugin-react-features/types';

const inlineConfig: ReactNoInlineFunctionsOptions = {
  allowInEventHandlers: true, // Allow simple event handlers
  minArraySize: 5, // Only warn for large lists
};

export default [
  {
    plugins: {
      'react-features': reactFeatures,
    },
    rules: {
      'react-features/react-no-inline-functions': ['warn', inlineConfig],
    },
  },
];

ESLint 8 (Legacy Config with JSDoc Types)

/** @type {import('eslint-plugin-react-features/types').ReactNoInlineFunctionsOptions} */
const inlineConfig = {
  allowInEventHandlers: true, // Allow simple event handlers
  minArraySize: 5, // Only warn for large lists
};

module.exports = {
  plugins: ['react-features'],
  rules: {
    'react-features/react-no-inline-functions': ['warn', inlineConfig],
  },
};

For more examples and patterns, see the package README.

Performance Impact

Array SizeRe-rendersImpact
1-10Low🟢 Minor
11-100Medium🟡 Moderate
100+High🔴 Significant

Comparison with Alternatives

Featurereact-no-inline-functionseslint-plugin-reactreact-hooks/exhaustive-deps
Inline Function Detection✅ Yes⚠️ Limited❌ No
Performance Metrics✅ Yes❌ No❌ No
Auto-Fix✅ Yes❌ No❌ No
LLM-Optimized✅ Yes❌ No❌ No
ESLint MCP✅ Optimized❌ No❌ No
useCallback Suggestions✅ Yes❌ No⚠️ Limited

Further Reading

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Dynamic Variable References

Why: Static analysis cannot trace values stored in variables or passed through function parameters.

// ❌ NOT DETECTED - Prop from variable
const propValue = computedValue;
<Component prop={propValue} /> // Computation not analyzed

Mitigation: Implement runtime validation and review code manually. Consider using TypeScript branded types for validated inputs.

Wrapped or Aliased Functions

Why: Custom wrapper functions or aliased methods are not recognized by the rule.

// ❌ NOT DETECTED - Custom wrapper
function myWrapper(data) {
  return internalApi(data); // Wrapper not analyzed
}
myWrapper(unsafeInput);

Mitigation: Apply this rule's principles to wrapper function implementations. Avoid aliasing security-sensitive functions.

Imported Values

Why: When values come from imports, the rule cannot analyze their origin or construction.

// ❌ NOT DETECTED - Value from import
import { getValue } from './helpers';
processValue(getValue()); // Cross-file not tracked

Mitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.