mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
Recurse rules
This commit is contained in:
parent
d98dfd40b5
commit
7cc8cd6127
5 changed files with 107 additions and 0 deletions
28
.rules/require_unique_id_props.mdc
Normal file
28
.rules/require_unique_id_props.mdc
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
```yaml
|
||||
name: require-unique-id-props
|
||||
description: Ensure unique key props are provided when mapping arrays to React elements
|
||||
globs: ['**/*.tsx', '**/*.jsx']
|
||||
alwaysApply: true
|
||||
```
|
||||
|
||||
When mapping arrays to React elements, each element must have a unique key prop to help React efficiently update the DOM.
|
||||
|
||||
❌ Bad - Missing key prop:
|
||||
```jsx
|
||||
{items.map((item) => (
|
||||
<Link href={`/dashboard/${item.id}`}>
|
||||
<Card>{item.name}</Card>
|
||||
</Link>
|
||||
))}
|
||||
```
|
||||
|
||||
✅ Good - With key prop:
|
||||
```jsx
|
||||
{items.map((item) => (
|
||||
<Link key={item.id} href={`/dashboard/${item.id}`}>
|
||||
<Card>{item.name}</Card>
|
||||
</Link>
|
||||
))}
|
||||
```
|
||||
|
||||
Keys should be stable, predictable, and unique among siblings.
|
||||
Loading…
Add table
Add a link
Reference in a new issue