--- title: sort-comp description: sort-comp rule tags: ['quality', 'react'] category: quality autofix: suggestions --- sort-comp rule # sort-comp > **Keywords:** React, component methods, ordering, lifecycle, code organization, ESLint rule, LLM-optimized Enforce component method ordering in React class components. This rule is part of [`eslint-plugin-react-features`](https://www.npmjs.com/package/eslint-plugin-react-features). ## Quick Summary | Aspect | Details | | -------------- | -------------------------------------------------------------------- | | **Severity** | Warning (organization) | | **Auto-Fix** | ❌ No (requires reordering) | | **Category** | React | | **ESLint MCP** | ✅ Optimized for ESLint MCP integration | | **Best For** | React class components with consistent style | ## Rule Details Enforces a consistent ordering of methods within React class components, making code more predictable and easier to navigate. ### Why This Matters | Issue | Impact | Solution | | ----------------------------- | ----------------------------------- | ---------------------------- | | 🔄 **Inconsistent structure** | Hard to find methods | Standardized ordering | | 🐛 **Review difficulty** | Different patterns across team | Consistent conventions | | 🔍 **Onboarding** | New devs struggle to navigate | Predictable structure | ## Default Order 1. `static-variables` - Static class properties 2. `static-methods` - Static methods 3. `instance-variables` - Instance properties 4. `lifecycle` - React lifecycle methods 5. `everything-else` - Custom methods 6. `render` - The render method (always last) The `lifecycle` group holds the constructor and React's lifecycle methods (`componentDidMount`, `shouldComponentUpdate`, `componentDidUpdate`, `componentWillUnmount`, …); their order among themselves is not checked. Member names are read in every spelling (`['render']()`). The class must extend React's `Component` or `PureComponent`, by binding, declared or as a class expression. ## Examples ### ❌ Incorrect ```tsx class UserProfile extends React.Component { // BAD: render before lifecycle render() { return