Understanding Keys
Keys help React identify which items have changed, been added, or removed. They're crucial for performance and correctness when rendering lists.
Why Keys Matter
Keys give elements a stable identity:
Loading React playground...
Good vs Bad Keys
Loading React playground...
When Index Keys Are OK
Index as key is acceptable in specific cases:
Loading React playground...
Generating Unique Keys
Loading React playground...
Exercise: Fix the Keys
Loading exercise...
Exercise: Composite Keys
Loading exercise...
Exercise: Key Validation
Loading exercise...
Key Takeaways
- Keys identify items - Help React track changes efficiently
- Use unique IDs - Database IDs or unique properties are best
- Avoid index as key - Only for static, append-only lists
- Composite keys - Combine properties when no single unique value
- Keys must be unique - Among siblings, not globally
التالي · الدرس 19 من 33
List Patterns and Filtering
قراءة 5 دقيقة
أنهيت 18 من 33 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

