-
Notifications
You must be signed in to change notification settings - Fork 348
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
Feature: Add ReasonReact.listToElement #192
Comments
Yay |
hmm. looks like perhaps this is defined in |
Oops, this is a duplicate of #140 |
ReactMini is a small experiment that has not much to do with ReasonReact itself and isn't shipped |
I implement it in this way: let listToReactElement = (list, fn) =>
list |> List.rev_map(fn) |> Array.of_list |> ReasonReact.arrayToElement;
let listToReactElementi = (list, fn) =>
list |> List.mapi(fn) |> Array.of_list |> ReasonReact.arrayToElement; |
This really kills perf and is not recommended |
So what is the best practice |
Use array. React children should probably not be modeled as a list |
But react children are a result of rendering application state. So that means changing all the lists in your app to arrays. |
Would also be nice with a few more. For example |
Does that mean this [1,2,3]
-> Belt.List.map( num => <div> {num -> string_of_int -> ReasonReact.string} </div>)
-> Belt.List.toArray
-> ReasonReact.array Is slower than [1,2,3]
-> Belt.List.toArray
-> Belt.Array.map( num => <div> {num -> string_of_int -> ReasonReact.string} </div> )
-> ReasonReact.array |
The problem is that |
Oh I see, so it might make sense to model the underlying data into arrays instead of lists from the start? For example decoding a list of users from the server, into an array instead of a list. |
Yes indeed, modelling everything as array from the start is indeed recommended. |
Just to simplify the conversion process further.
listToElement : list(reactElement) => arrayToElement(Array.of_list(list))
The text was updated successfully, but these errors were encountered: