Skip to content

Commit 9c12c5a

Browse files
authored
Update keeping-components-pure.md
1 parent f86fe8c commit 9c12c5a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/content/learn/keeping-components-pure.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,28 @@ You could think of your components as recipes: if you follow them and don't intr
8585

8686
<Illustration src="/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" />
8787

88-
### JSX Equality and Purity
88+
#### What does "same JSX" mean?
8989

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.
9697

97-
#### Example
9898
<Sandpack>
9999

100100
```jsx
101101
// These are considered equal (same structure):
102102
<Child config={{ color: 'red' }} />
103103
<Child config={{ color: 'red' }} />
104104

105-
// These are NOT equal (different structure):
106-
<Child config={{ color: 'red' }} />
105+
// These are NOT equal (different structure or type):
107106
<Child config={{ color: 'blue' }} />
107+
<Child />
108+
<DifferentComponent />
108109
```
109-
110110
</Sandpack>
111111

112112
## Side Effects: (un)intended consequences {/*side-effects-unintended-consequences*/}

0 commit comments

Comments
 (0)