Skip to content

Commit

Permalink
doc: update pitfalls
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpo authored Aug 22, 2024
1 parent 3d723f8 commit 89694b7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion docs/pitfalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- [Explanations](#explanations)
- [Accessibility](#accessibility)

## Conditional rendering
## Conditional rendering & dynamic ordering

### TLDR

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

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.
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.
It will force the children to re-render but we have no better recommendation yet!

```tsx
// DON'T ❌
<View>
{elements.map((element) => <Element element={element} />)}
</View>

// DO ✅
<View>
{elements.map((element, index) =>
<SpatialNavigationNode key={index}>
<Element element={element} />)
</SpatialNavigationNode>
}
</View>
```
### Explanations
If you try to hide and then show a button again naively using the library, you’ll encounter an issue.
Expand Down

0 comments on commit 89694b7

Please sign in to comment.