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
If a component contains more than one child, then `rehydrateChildren` will return a `React.Fragment`. This may affect your components if you use `React.Children`, in order to iterate over child components from a parent component.
37
+
38
+
To overcome this, you have two options:
39
+
40
+
1. In your rehydrator function, you can check the type of the children you get back. If it's a `React.Fragment`, you can pass through its children. This isn't generally recommended, but it will work in a pinch.
2. Unwrap `React.Fragment` while you iterate over children. This has the added advantage of making your component work with fragments, rather than patching support into the rehydrator.
55
+
56
+
```javascript
57
+
constgetTitles=children=> {
58
+
consttitles= [];
59
+
60
+
React.Children.forEach(children, child=> {
61
+
if (child.type===React.Fragment) {
62
+
// Recursively unwrap `React.Fragment`'s children, get their titles,
63
+
// and add them to the return value.
64
+
titles.push(...getTitles(child.props.children));
65
+
} elseif (child.type=== MySubcomponent) {
66
+
// For a specific component type, extract the title prop.
0 commit comments