# react/jsx-sort-props
📝 Enforce props alphabetical sorting.
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
Some developers prefer to sort props names alphabetically to be able to find necessary props easier at the later time. Others feel that it adds complexity and becomes burden to maintain.
## Rule Details
This rule checks all JSX components and verifies that all props are sorted alphabetically. A spread attribute resets the verification. The default configuration of the rule is case-sensitive.
Examples of **incorrect** code for this rule:
```jsx
```
Examples of **correct** code for this rule:
```jsx
;
;
```
## Rule Options
```js
...
"react/jsx-sort-props": [, {
"callbacksLast": ,
"shorthandFirst": ,
"shorthandLast": ,
"multiline": "ignore" | "first" | "last",
"ignoreCase": ,
"noSortAlphabetically": ,
"reservedFirst": |>,
"sortFirst": >,
"locale": "auto" | "any valid locale"
}]
...
```
### `ignoreCase`
When `true` the rule ignores the case-sensitivity of the props order.
Examples of **correct** code for this rule
```jsx
```
### `callbacksLast`
When `true`, callbacks must be listed after all other props, even if `shorthandLast` is set :
```jsx
```
### `shorthandFirst`
When `true`, short hand props must be listed before all other props, but still respecting the alphabetical order:
```jsx
```
### `shorthandLast`
When `true`, short hand props must be listed after all other props (unless `callbacksLast` is set), but still respecting the alphabetical order:
```jsx
```
### `multiline`
Enforced sorting for multiline props
- `ignore`: Multiline props will not be taken in consideration for sorting.
- `first`: Multiline props must be listed before all other props (unless `shorthandFirst` is set), but still respecting the alphabetical order.
- `last`: Multiline props must be listed after all other props (unless either `callbacksLast` or `shorthandLast` are set), but still respecting the alphabetical order.
Defaults to `ignore`.
```jsx
// 'jsx-sort-props': [1, { multiline: 'first' }]
// 'jsx-sort-props': [1, { multiline: 'last' }]
```
### `noSortAlphabetically`
When `true`, alphabetical order is **not** enforced:
```jsx
```
### `reservedFirst`
This can be a boolean or an array option.
When `reservedFirst` is defined, React reserved props (`children`, `dangerouslySetInnerHTML` - **only for DOM components**, `key`, and `ref`) must be listed before all other props, but still respecting the alphabetical order:
```jsx
```
If given as an array, the array's values will override the default list of reserved props. **Note**: the values in the array may only be a **subset** of React reserved props.
With `reservedFirst: ["key"]`, the following will **not** warn:
```jsx
```
### `sortFirst`
When `sortFirst` is defined as an array of prop names, those props must be listed before all other props, maintaining the exact order specified in the array. This option has the highest priority and takes precedence over all other sorting options (including `reservedFirst`, `shorthandFirst`, `callbacksLast`, and `multiline`).
The prop names in the array are matched case-sensitively by default, but respect the `ignoreCase` option when enabled.
Examples of **incorrect** code for this rule:
```jsx
// 'jsx-sort-props': [1, { sortFirst: ['className'] }]
```
Examples of **correct** code for this rule:
```jsx
// 'jsx-sort-props': [1, { sortFirst: ['className'] }]
// 'jsx-sort-props': [1, { sortFirst: ['className', 'id'] }]
// 'jsx-sort-props': [1, { sortFirst: ['className'], ignoreCase: true }]
```
### `locale`
Defaults to `"auto"`, meaning, the locale of the current environment.
Any other string provided here may be passed to `String.prototype.localeCompare` - note that an unknown or invalid locale may throw an exception and crash.
## When Not To Use It
This rule is a formatting preference and not following it won't negatively affect the quality of your code. If alphabetizing props isn't a part of your coding standards, then you can leave this rule off.