no-children-prop
no-children-prop rule
Keywords: React, children, props, composition, ESLint rule, best practices, LLM-optimized
Prevent passing children as a prop. This rule is part of eslint-plugin-react-features.
Quick Summary
| Aspect | Details |
|---|---|
| Severity | Warning (style) |
| Auto-Fix | ❌ No (requires restructuring) |
| Category | React |
| ESLint MCP | ✅ Optimized for ESLint MCP integration |
| Best For | Consistent JSX patterns |
Rule Details
Passing children as a prop instead of nesting is less readable and can cause issues.
Why This Matters
| Issue | Impact | Solution |
|---|---|---|
| 📖 Readability | Less intuitive structure | Use nested children |
| 🔄 Consistency | Mixed patterns | Standardize |
| 🐛 Edge cases | Prop overwrite issues | Natural nesting |
Examples
❌ Incorrect
<Component children={<span>Hello</span>} />
<Component children="Hello" />
<Component children={[<span key="1">A</span>, <span key="2">B</span>]} />✅ Correct
<Component>
<span>Hello</span>
</Component>
<Component>Hello</Component>
<Component>
<span key="1">A</span>
<span key="2">B</span>
</Component>Configuration Examples
Basic Usage
{
rules: {
'react-features/no-children-prop': 'warn'
}
}Related Rules
jsx-key- Keys in children lists
Further Reading
- Composition vs Inheritance - React docs
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 analyzedMitigation: 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 trackedMitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.