From f86fe8c5bb1674a00f9b3d98ddb68f8cea320263 Mon Sep 17 00:00:00 2001 From: Alex Pacheco <54867692+vib3-ch3ck@users.noreply.github.com> Date: Tue, 29 Apr 2025 09:50:08 -0400 Subject: [PATCH 1/3] Update keeping-components-pure.md --- src/content/learn/keeping-components-pure.md | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/content/learn/keeping-components-pure.md b/src/content/learn/keeping-components-pure.md index 6d4f55763fa..5d6ab50f0b0 100644 --- a/src/content/learn/keeping-components-pure.md +++ b/src/content/learn/keeping-components-pure.md @@ -85,6 +85,30 @@ You could think of your components as recipes: if you follow them and don't intr +### JSX Equality and Purity + +React considers two JSX values to be "equal" for purity purposes if: +1. **Their types are identical** (e.g., both ``). +2. **Their props are deeply equal**: + - Primitive props (`string`, `number`, `boolean`) must be `===` equal. + - Object/array props must be *structurally equivalent* (same keys/values, regardless of reference). +3. **Their `key` and `ref` props (if any) are equal**. + +#### Example + + +```jsx +// These are considered equal (same structure): + + + +// These are NOT equal (different structure): + + +``` + + + ## Side Effects: (un)intended consequences {/*side-effects-unintended-consequences*/} React's rendering process must always be pure. Components should only *return* their JSX, and not *change* any objects or variables that existed before rendering—that would make them impure! From 9c12c5a308ad15023fd7c8a8b0c5a5de2998a94d Mon Sep 17 00:00:00 2001 From: Alex Pacheco <54867692+vib3-ch3ck@users.noreply.github.com> Date: Tue, 29 Apr 2025 09:52:17 -0400 Subject: [PATCH 2/3] Update keeping-components-pure.md --- src/content/learn/keeping-components-pure.md | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/content/learn/keeping-components-pure.md b/src/content/learn/keeping-components-pure.md index 5d6ab50f0b0..89d3706f98f 100644 --- a/src/content/learn/keeping-components-pure.md +++ b/src/content/learn/keeping-components-pure.md @@ -85,16 +85,16 @@ You could think of your components as recipes: if you follow them and don't intr -### JSX Equality and Purity +#### What does "same JSX" mean? -React considers two JSX values to be "equal" for purity purposes if: -1. **Their types are identical** (e.g., both ``). -2. **Their props are deeply equal**: - - Primitive props (`string`, `number`, `boolean`) must be `===` equal. - - Object/array props must be *structurally equivalent* (same keys/values, regardless of reference). -3. **Their `key` and `ref` props (if any) are equal**. +For two JSX values to be considered equal in React's purity model: + +- **Type equality**: They must be the same component or HTML tag (e.g., `