Halogen provides a handy RefLabel
, that allows to refer an element from elsewhere.
So for example, you can make a modal window component, and then use its ref
in another component to call showModal
or close
on it.
Upstream React provides useRef
hook that does the same.
However, I can’t seem to find anything in “react-basic-hooks”. Can I do something similar with it?
FWIW, every react-hooks JSX (an element) has special value in its record ref :: Ref (Nullable Node)
. But this alone doesn’t do much. For this to work there presumably should be some JSX -> Node
function, but such does not exist. I also tried cloning both react-hooks
and its dep react-basic
and did a git grep --color=always -P "\bNode\b" | grep -v "ref :: Ref"
, but got nothing relevant.
So it’s an open question, which if no one knows I presume might be best to ask the devs on the Github, because clearly they started working on the facility, but… Idk, it’s either they never finished it, or they did, but it is something very hidden and undocumented.
So, it turns out the function useRef
may be used, but as you can see by the research done here as it stands it is completely impossible to guess how.
I proposed adding helpers/wrappers which would simplify users’ life a lot, but surprisingly was met with opposition.
A month later I made another stab at the sad state of matters, and sent a PR which simply documents useRef
and describes helpers you can use. Idk how it’s going to go this time, I hope at least somewhat better… Will see.