purescript-contrib/purescript-react

It doesn't appear to be possible to do much with Refs

iand675 opened this issue · 3 comments

Refs is an opaque type, and there's no exported accessors to pull data out from Refs. Similarly, there doesn't seem to be any support in the Props module for establishing a ref in the first place. I'm using a 3rd-party component that has methods on it that need to be triggered from outside, and as best as I can tell, establishing it as a ref is the only real way to do that.

paf31 commented

You should be able to call getRefs in event handlers and lifecycle methods. The Refs type, however, is abstract, and you would have to access it using the FFI or some other approach like purescript-foreign.

ethul commented

I think it is a good point about the ref attribute.

From the docs, it looks like react supports adding a ref callback or a ref string. I think it may be useful to support these cases. Maybe we can add two functions in React.DOM.Props to support this? I'd be happy to add these or a PR also works.

Agreed that currently, the way to go about accessing the Refs type is via the FFI.

I wonder if it might be worth representing Refs as:

type Refs = StrMap ReactComponent

I am not sure if that would be the way to go or not, or how much it buys us, but we could define functions like focus that accept a ReactComponent, etc.

I am open to thoughts and ideas on this, or discussing it further.

ethul commented

Closed via #100