You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/learn/keeping-components-pure.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,28 +85,28 @@ You could think of your components as recipes: if you follow them and don't intr
85
85
86
86
<Illustrationsrc="/images/docs/illustrations/i_puritea-recipe.png"alt="A tea recipe for x people: take x cups of water, add x spoons of tea and 0.5x spoons of spices, and 0.5x cups of milk" />
87
87
88
-
###JSX Equality and Purity
88
+
#### What does "same JSX" mean?
89
89
90
-
React considers two JSX values to be "equal" for purity purposes if:
91
-
1.**Their types are identical** (e.g., both `<Child />`).
92
-
2.**Their props are deeply equal**:
93
-
- Primitive props (`string`, `number`, `boolean`) must be `===` equal.
94
-
- Object/array props must be *structurally equivalent* (same keys/values, regardless of reference).
95
-
3.**Their `key` and `ref` props (if any) are equal**.
90
+
For two JSX values to be considered equal in React's purity model:
91
+
92
+
-**Type equality**: They must be the same component or HTML tag (e.g., `<Button />` vs `<div>`).
93
+
-**Prop equality**:
94
+
- Primitive props (`string`, `number`, `boolean`) must be identical (`===`).
95
+
- Object/array props must have *equivalent structure* (same keys/values, even if references differ).
96
+
-**Special props**: `key` and `ref` (if present) must be identical.
96
97
97
-
#### Example
98
98
<Sandpack>
99
99
100
100
```jsx
101
101
// These are considered equal (same structure):
102
102
<Child config={{ color:'red' }} />
103
103
<Child config={{ color:'red' }} />
104
104
105
-
// These are NOT equal (different structure):
106
-
<Child config={{ color:'red' }} />
105
+
// These are NOT equal (different structure or type):
107
106
<Child config={{ color:'blue' }} />
107
+
<Child />
108
+
<DifferentComponent />
108
109
```
109
-
110
110
</Sandpack>
111
111
112
112
## Side Effects: (un)intended consequences {/*side-effects-unintended-consequences*/}
0 commit comments