Skip to content

Commit 89694b7

Browse files
authored
doc: update pitfalls
1 parent 3d723f8 commit 89694b7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/pitfalls.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- [Explanations](#explanations)
77
- [Accessibility](#accessibility)
88

9-
## Conditional rendering
9+
## Conditional rendering & dynamic ordering
1010

1111
### TLDR
1212

@@ -26,6 +26,26 @@ If navigation elements are conditionnally visible, it is necessary to wrap them
2626
</View>
2727
```
2828

29+
The same goes for mapping over a list of elements that can change. The trick in that case is to wrap the elements with a SpatialNavigationNode that is keyed by the list index.
30+
Yes, this is bad practice in general, but it is justified here because we really want the SpatialNavigationNode components to never change even if the list moves.
31+
It will force the children to re-render but we have no better recommendation yet!
32+
33+
```tsx
34+
// DON'T ❌
35+
<View>
36+
{elements.map((element) => <Element element={element} />)}
37+
</View>
38+
39+
// DO ✅
40+
<View>
41+
{elements.map((element, index) =>
42+
<SpatialNavigationNode key={index}>
43+
<Element element={element} />)
44+
</SpatialNavigationNode>
45+
}
46+
</View>
47+
```
48+
2949
### Explanations
3050
3151
If you try to hide and then show a button again naively using the library, you’ll encounter an issue.

0 commit comments

Comments
 (0)