-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Accept Ref Objects as Refs? #10581
Comments
The thing that is special about OCaml is that there is already a first-class language feature for these. So you would by-pass |
Each ref object being allocated separately is not great, but refs are perhaps not prevalent enough for this to really be a concern, and in practice this would probably even end up being faster as most people use the inline fat-arrow syntax which is (currently) inefficient. Could one imagine a form that would work for arrays of elements too? (i.e. when you want to keep a ref to each of the items in a list) Otherwise, that seems problematic for users to achieve in React if they prefer this style. |
I'm guessing it wouldn't be unthinkable to have native support for refs either? It would just act exactly as the value it is referencing, except there's some way of updating the ref, e.g. |
I suppose one issue is that this doesn't actually compile to So maybe this does indeed have to use ref callbacks as the interop layer. cc @chenglou |
The record compiles to an array of a single item. It's an internal representation (though unlikely to change). A bit torn... |
Out in 16.3 |
Reason React uses first class OCaml refs to store mutable values (instead of on
this
instances).These are basically just an object with a mutable
contents
property. These can be updated with callback refsn => ref.contents = n
but it would be a nice convenience feature to just have that built-in.We could also make these first class objects on isomorphic React.
Basically the implementation would just be:
This is something that needs to be implemented in the core runtime and not as part of any particular component API since refs cross that boundary.
cc @adamjernst
The text was updated successfully, but these errors were encountered: