Skip to content

Commit a4f38b5

Browse files
committed
[docs/react] Fix keys and arrays example
* Use correctly `Belt.Array.mapWithIndex` * Convert index to string * Highlight first line (as a newcommer to rescript you're likely to ignore that you need a different function to access index within a map call).
1 parent dcad394 commit a4f38b5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pages/docs/react/latest/arrays-and-keys.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ let items = Belt.Array.map(todos, todo => {
4141

4242
If you don’t have stable IDs for rendered items, you may use the item index as a key as a last resort:
4343

44-
```res {2,3}
45-
let items = Belt.Array.mapWithIndex(todos, (todo, i) => {
44+
```res {1..3}
45+
let items = Belt.Array.mapWithIndex(todos, (i, todo) => {
4646
// Only do this if items have no stable id
47-
<li key={i}>
47+
<li key={Belt.Int.toString(i)}>
4848
{todo.text}
4949
</li>
5050
});

0 commit comments

Comments
 (0)