learn: fix type bug in reasonml tutorial (#2564)

* Error on line 72

That line throws an error:
```ocaml
53 │         let onlineUsers = Array.map(u => <UserItem user=u />, data##on
       line_users);
  54 │
  55 │         let onlineUsersTitle =

  This has type:
    Js.Array.t({. "id": option(string), "user": option({. "name": string})})
      (defined as
      array({. "id": option(string), "user": option({. "name": string})}))
  But somewhere wanted:
    array({.. "name": string})
  The first object type has no method name

>>>> Finish compiling(exit: 1)
```

Works like this:

```ocaml
let online_users = data##online_users->Belt.Array.keepMap(x => x##user);
let onlineUsers = Array.map(u => <UserItem user=u />, online_users);
```
Or however you want to do it.

* Per pull conversation

added piped version, combining functions.
This commit is contained in:
Alain Armand 2019-08-27 06:52:09 -04:00 committed by Shahidh K Muhammed
parent eac5681100
commit ce11953038

View File

@ -69,7 +69,8 @@ let make = () => {
+ } + }
+ | Data(data) => { + | Data(data) => {
- let onlineUsers = Array.map(u => <UserItem user={u}/>, sampleUsers); - let onlineUsers = Array.map(u => <UserItem user={u}/>, sampleUsers);
+ let onlineUsers = Array.map(u => <UserItem user={u}/>, data##online_users); + let onlineUsers = data##online_users->Belt.Array.keepMap(x => x##user)
+ |> Array.map(u => <UserItem user=u />);
- let onlineUsersTitle = "Online users - " ++ string_of_int(Array.length(sampleUsers)); - let onlineUsersTitle = "Online users - " ++ string_of_int(Array.length(sampleUsers));
+ let onlineUsersTitle = "Online users - " ++ string_of_int(Array.length(data##online_users)); + let onlineUsersTitle = "Online users - " ++ string_of_int(Array.length(data##online_users));
<div className="onlineUsersWrapper"> <div className="onlineUsersWrapper">