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/escape-hatches.md
+49-12Lines changed: 49 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,28 +31,65 @@ const ref = useRef(0);
31
31
32
32
Like state, refs are retained by React between re-renders. However, setting state re-renders a component. Changing a ref does not! You can access the current value of that ref through the `ref.current` property.
33
33
34
+
For example, this Effect depends on the `options` object which gets re-created every time you edit the input:
35
+
36
+
> ⚠️ **Note (example intentionally shows a problematic pattern).**
37
+
>
38
+
> The code below purposely shows a case where an `options` object is recreated on every render to demonstrate why that would re-run an Effect. The sandbox linter will show an error for this example — that is expected. See the following section for a corrected version.
A ref is like a secret pocket of your component that React doesn't track. For example, you can use refs to store [timeout IDs](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#return_value), [DOM elements](https://developer.mozilla.org/en-US/docs/Web/API/Element), and other objects that don't impact the component's rendering output.
0 commit comments