reason-react icon indicating copy to clipboard operation
reason-react copied to clipboard

Type children key statically

Open chenglou opened this issue 8 years ago • 3 comments

We use currying for ref and key already. There might be some phantom types/GADT things we can use here to statically type the fact that children key exists. More info: https://github.com/reasonml/rehydrate/blob/6808bf1a19e701214e4456967b4aab155d79802c/src/reactRe.re#L60

Alternatively, @jordwalke can take the occasion to design this away without needing fancy types, with his OrderedMap idea (jordan can talk more about this).

The benefit is that this is the last feature we need in order to completely bypass createElement (which sets up the key warning, that we currently piggyback on), and make every JSX render twice faster.

chenglou avatar Feb 10 '17 00:02 chenglou

Why don't we throw in an OrderedSet as keys or something as an experiment? I'm wondering why we even have to supply keys to React. Is there a reason the reconciler can't make those up?

IwanKaramazow avatar Feb 11 '17 10:02 IwanKaramazow

We can have that; just that it's not clear whether it'll work out yet (not many people understand the semantics of nested arrays keys btw). In the meantime, having children statically typed would be great anyway! We can tackle on OrderedSet later too.

I'm thinking it's also not worse in terms of verbosity. Right now it's ReactRe.stringToElement and some others...

chenglou avatar Feb 12 '17 09:02 chenglou

@chenglou can you explain the issues with nested arrays?

cristianoc avatar Mar 19 '17 19:03 cristianoc