Hasty Briefsbeta

Bilingual

Why Do React Elements Have a $$typeof Property? — overreacted

13 hours ago
  • React elements are plain objects created by JSX (a function call) that include type, props, key, ref, and a $$typeof property.
  • The $$typeof property with a Symbol value is a security feature in React 0.14+ to prevent XSS attacks from malicious JSON objects.
  • If the server has a security hole returning JSON instead of text, the $$typeof Symbol check rejects invalid elements because Symbols cannot be included in JSON.
  • In browsers without Symbol support, $$typeof is set to the number 0xeac7 (which resembles 'React') for consistency, though with less protection.