Skip to content

fix the list rendering example #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions pages/docs/react/latest/arrays-and-keys.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,24 @@ In case you ever want to render a `list` of items, you can do something like thi

```res
type todo = {id: string, text: string}
let todoList = list{
{id: "todo1", text: "Todo 1"},
{id: "todo2", text: "Todo 2"}
}

let items =
todoList
->Belt.List.toArray
->Belt.List.map((todo) => {
<li key={todo.id}>
{React.string(todo.text)}
</li>
})
@react.component
let make = () => {
let todoList = list{
{id: "todo1", text: "Todo 1"},
{id: "todo2", text: "Todo 2"},
}

let items =
todoList
->Belt.List.toArray
->Belt.Array.map(todo => {
<li key={todo.id}> {React.string(todo.text)} </li>
})

<div> {React.array(items)} </div>
}

<div> {React.array(items)} </div>
```

We use `Belt.List.toArray` to convert our list to an array before creating our `array<React.element>`. Please note that using `list` has performance impact due to extra conversion costs.
Expand Down