Compile ref
to getter and setter?
#1078
otonashixav
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
This is an interesting idea. I didn't think of it because well writing to props generally isn't good but this an example where that is what you want. Using the getter has the benefit of being able to use the ref locally as well. As in skip even having You could just do this if I'm thinking about this right: function Comp(props: { ref?: HTMLDivElement }) {
onMount(() => fn(props.ref));
return <div ref={props.ref} />
}; I think it is breaking though, because anyone expecting to call it as a function can't. Still I think is probably better in general. I'd love to move this way for 2.0. It won't break the common case so I think that it will be fine to change. But it will drastically simplify the rest. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Doing so would allow
props.ref = something
to work as if it wereprops.ref(something)
, e.g.Not sure if this breaks anything. This would help with typescript (somewhat, types would still be awkward since props.ref can't be different types inside and outside the component to match the compiled output) since currently we have to either typecast or do redundant checks to narrow the ref type to a function, and it also allows setting the ref without checking that the ref actually exists:
Beta Was this translation helpful? Give feedback.
All reactions