How can I execute a function from parent?
How does
ref
work? I want to execute a function from parent, something like this:
Is something like this possible?8 Replies
ref
is a special prop that compiles to ref={e => your_variable = e}
. Other props don't get that treatment. Just use the function form
So to pass a ref from child (or any other prop) you do props.ref(your_value)
I meant to say that i wanna execute a function from parent, I wanna make my own
ref
kinda thing
ah 🤔
That seems to work, thanks 🙂
do you know how i could use it with typescript?
See solids types for reference
I saw
Ref
but that didnt seem to work properlyit's
T | (v: T) => void
or something
but you have to lie to typescript when using it, as it always compiles to a function so it cannot be T
ah
there is
mergeRefs
in solid-primitives that aims to help with refs a little bit. But it's not necessary. I'll just hide the type assertion as implementation detaili see
ill just use
as any
for now 😅