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/reference/react/Fragment.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ title: <Fragment> (<>...</>)
6
6
7
7
`<Fragment>`, often used via `<>...</>` syntax, lets you group elements without a wrapper node.
8
8
9
-
<Experimental> Fragments can also accept refs, which enable interacting with underlying DOM nodes without adding wrapper elements. See reference and usage below.</Experimental>
9
+
<Canary> Fragments can also accept refs, which enable interacting with underlying DOM nodes without adding wrapper elements. See reference and usage below.</Canary>
10
10
11
11
```js
12
12
<>
@@ -30,9 +30,9 @@ Wrap elements in `<Fragment>` to group them together in situations where you nee
30
30
#### Props {/*props*/}
31
31
32
32
-**optional**`key`: Fragments declared with the explicit `<Fragment>` syntax may have [keys.](/learn/rendering-lists#keeping-list-items-in-order-with-key)
33
-
- <ExperimentalBadge /> **optional**`ref`: A ref object (e.g. from [`useRef`](/reference/react/useRef)) or [callback function](/reference/react-dom/components/common#ref-callback). React provides a `FragmentInstance` as the ref value that implements methods for interacting with the DOM nodes wrapped by the Fragment.
33
+
- <CanaryBadge /> **optional**`ref`: A ref object (e.g. from [`useRef`](/reference/react/useRef)) or [callback function](/reference/react-dom/components/common#ref-callback). React provides a `FragmentInstance` as the ref value that implements methods for interacting with the DOM nodes wrapped by the Fragment.
When you pass a ref to a fragment, React provides a `FragmentInstance` object with methods for interacting with the DOM nodes wrapped by the fragment:
38
38
@@ -64,7 +64,7 @@ When you pass a ref to a fragment, React provides a `FragmentInstance` object wi
64
64
65
65
- React does not [reset state](/learn/preserving-and-resetting-state) when you go from rendering `<><Child /></>` to `[<Child />]` or back, or when you go from rendering `<><Child /></>` to `<Child />` and back. This only works a single level deep: for example, going from `<><><Child /></></>` to `<Child />` resets the state. See the precise semantics [here.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
66
66
67
-
- <ExperimentalBadge /> If you want to pass `ref` to a Fragment, you can't use the `<>...</>` syntax. You have to explicitly import `Fragment` from `'react'` and render `<Fragment ref={yourRef}>...</Fragment>`.
67
+
- <CanaryBadge /> If you want to pass `ref` to a Fragment, you can't use the `<>...</>` syntax. You have to explicitly import `Fragment` from `'react'` and render `<Fragment ref={yourRef}>...</Fragment>`.
68
68
69
69
---
70
70
@@ -242,7 +242,7 @@ function PostBody({ body }) {
242
242
243
243
---
244
244
245
-
### <ExperimentalBadge /> Using Fragment refs for DOM interaction {/*using-fragment-refs-for-dom-interaction*/}
245
+
### <CanaryBadge /> Using Fragment refs for DOM interaction {/*using-fragment-refs-for-dom-interaction*/}
246
246
247
247
Fragment refs allow you to interact with the DOM nodes wrapped by a Fragment without adding extra wrapper elements. This is useful for event handling, visibility tracking, focus management, and replacing deprecated patterns like `ReactDOM.findDOMNode()`.
248
248
@@ -262,7 +262,7 @@ function ClickableFragment({ children, onClick }) {
262
262
```
263
263
---
264
264
265
-
### <ExperimentalBadge /> Tracking visibility with Fragment refs {/*tracking-visibility-with-fragment-refs*/}
265
+
### <CanaryBadge /> Tracking visibility with Fragment refs {/*tracking-visibility-with-fragment-refs*/}
266
266
267
267
Fragment refs are useful for visibility tracking and intersection observation. This enables you to monitor when content becomes visible without requiring the child Components to expose refs:
268
268
@@ -309,7 +309,7 @@ This pattern is an alternative to Effect-based visibility logging, which is an a
309
309
310
310
---
311
311
312
-
### <ExperimentalBadge /> Focus management with Fragment refs {/*focus-management-with-fragment-refs*/}
312
+
### <CanaryBadge /> Focus management with Fragment refs {/*focus-management-with-fragment-refs*/}
313
313
314
314
Fragment refs provide focus management methods that work across all DOM nodes within the Fragment:
0 commit comments