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/manipulating-the-dom-with-refs.md
-10Lines changed: 0 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -309,16 +309,6 @@ li {
309
309
}
310
310
```
311
311
312
-
```json package.json hidden
313
-
{
314
-
"dependencies": {
315
-
"react": "canary",
316
-
"react-dom": "canary",
317
-
"react-scripts": "^5.0.0"
318
-
}
319
-
}
320
-
```
321
-
322
312
</Sandpack>
323
313
324
314
In this example, `itemsRef` doesn't hold a single DOM node. Instead, it holds a [Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map) from item ID to a DOM node. ([Refs can hold any values!](/learn/referencing-values-with-refs)) The [`ref` callback](/reference/react-dom/components/common#ref-callback) on every list item takes care to update the Map:
Copy file name to clipboardExpand all lines: src/content/reference/react/StrictMode.md
-30Lines changed: 0 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -952,16 +952,6 @@ li {
952
952
}
953
953
```
954
954
955
-
```json package.json hidden
956
-
{
957
-
"dependencies": {
958
-
"react":"beta",
959
-
"react-dom":"beta",
960
-
"react-scripts":"^5.0.0"
961
-
}
962
-
}
963
-
```
964
-
965
955
</Sandpack>
966
956
967
957
@@ -1104,16 +1094,6 @@ li {
1104
1094
}
1105
1095
```
1106
1096
1107
-
```json package.json hidden
1108
-
{
1109
-
"dependencies": {
1110
-
"react":"beta",
1111
-
"react-dom":"beta",
1112
-
"react-scripts":"^5.0.0"
1113
-
}
1114
-
}
1115
-
```
1116
-
1117
1097
</Sandpack>
1118
1098
1119
1099
**With Strict Mode, you immediately see that there is a problem**. Strict Mode runs an extra setup+cleanup cycle for every callback ref. This callback ref has no cleanup logic, so it adds refs but doesn't remove them. This is a hint that you're missing a cleanup function.
@@ -1241,16 +1221,6 @@ li {
1241
1221
}
1242
1222
```
1243
1223
1244
-
```json package.json hidden
1245
-
{
1246
-
"dependencies": {
1247
-
"react":"beta",
1248
-
"react-dom":"beta",
1249
-
"react-scripts":"^5.0.0"
1250
-
}
1251
-
}
1252
-
```
1253
-
1254
1224
</Sandpack>
1255
1225
1256
1226
Now on inital mount in StrictMode, the ref callbacks are all setup, cleaned up, and setup again:
0 commit comments